%! % Homework 2 % Question 1 % - procedure definitions ---------------------------------- % s /square { 4 dict begin /s exch def 0 0 moveto s 0 rlineto 0 s rlineto s neg 0 rlineto closepath end } def % [..] [..] [..] /triangle { 8 dict begin /C exch def /B exch def /A exch def A 0 get A 1 get moveto B 0 get B 1 get lineto C 0 get C 1 get lineto closepath end } def % - the drawing -------------------------------------------------- gsave 72 72 scale 0.012 setlinewidth 4 5 translate /a 2.5 0.25 mul def /b 4 0.25 mul def /c a a mul b b mul add sqrt def /x a a mul c div def /y a b mul c div def % - draw the squares first ------------------------------------------ gsave newpath -90 rotate c square stroke grestore gsave newpath b a atan rotate a square stroke grestore gsave x y translate newpath a b atan neg rotate b square stroke grestore % - draw the plumb line ------------------------------------------ gsave 0.6 setgray newpath x y moveto x c neg lineto stroke grestore % - draw the left triangles -------------------------------------- gsave 1 0 0 setrgbcolor newpath [0 0] [0 c neg] [x y] triangle stroke grestore gsave 1 0 0 setrgbcolor newpath [0 0] [y neg x] [c 0] triangle stroke grestore % - draw the right triangles -------------------------------------- gsave 0 0 1 setrgbcolor newpath [c c neg] [c 0] [x y] triangle stroke grestore gsave 0 0 1 setrgbcolor c 0 translate b a atan rotate newpath [0 0] [b 0] [a neg b] triangle stroke grestore grestore showpage