ExamplePythagoras

Example taken from asymptote gallery.

Drawj2d output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! drawj2d -T svg -r96 -W 100 -H 100 ExamplePythagoras.hcl

offset 80 80
unitlength 10

set a 3
set b 4

# vertices
set ML "-[+ $a $b] -$b" ; # middle left
set BM "-$b 0"          ; # bottom middle
set BL "-[+ $a $b] 0"   ; # bottom left

# draw squares
m 0 0; rectangle -[+ $a $b] -[+ $a $b];
m $BM; lr $b -$a; lr -$a -$b; lr -$b $a; l $BM;

# draw dimension lines
pen red 0.2
font tex 6; # Sets font to computer modern, 6mm
set d [mm 10]
m [++ $BL "0 $d"]
dimlinerel $a 0  a
dimlinerel $b 0  b
dimline [geom.parallel "0 -$a" $BM $d] c
m "$d 0"
dimlinerel 0 -$a a
dimlinerel 0 -$b b

# draw perpendicular sign
pen blue
dimangle $ML [++ $ML "$b -$a"] $BM
m "0 0"; dimangle 180 270

# write equation
m $ML; mr [mm 4  4]; font
texlabel {\displaystyle  c^2 = (a+b)^2 - 4 \frac{a b}{2} = a^2 + b^2}

Related

Wiki: Examples

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.