%! % --- Part 1. Make global definitions ------------------------------------------ % builds the path outlining a square with corners % (0, 0), (s, 0), (s, s), (0, s) /buildsquare { 0 0 moveto s 0 lineto s s lineto 0 s lineto closepath } def /a 3 def /b 4 def /c a dup mul b dup mul add sqrt def % find the vertex (x, y) /x a c div a mul def /y b c div a mul def % and some analgous ratios /X a c div b mul def /Y b c div b mul def /N 8 def % --- Part 2. Draw, run the loop ------------------------------------------ /A 0 def /dA 90 N 1 sub div def N { gsave 72 dup scale 1 72 div setlinewidth 2.5 5.5 translate 0.6 dup scale % --- draw the three squares ------------------------------- /s c def gsave -90 rotate newpath buildsquare stroke grestore /s a def gsave b a atan rotate newpath buildsquare stroke grestore /s b def gsave c 0 translate b a atan rotate newpath buildsquare stroke grestore % --- the vertical line ------------------------------------------------ newpath x y moveto 0 y c add neg rlineto stroke % --- the red triangle ------------------------------------------------ gsave A rotate newpath 0 0 moveto x y lineto 0 c neg lineto closepath gsave 1 0 0 setrgbcolor fill grestore stroke grestore % --- the other triangles ------------------------------------------------ newpath 0 0 moveto y neg x lineto c 0 lineto closepath stroke newpath c 0 moveto c X add Y lineto 0 0 lineto closepath stroke newpath c 0 moveto x y lineto c c neg lineto closepath stroke grestore showpage /A A dA add def } repeat