%! % 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 % -------------------------------------------------------------- 72 dup scale 1 72 div setlinewidth 2.5 5.5 translate 0.6 dup scale % --- draw the three squares ------------------------------- /s 5 def gsave -90 rotate newpath buildsquare stroke grestore /s 3 def gsave 4 3 atan rotate newpath buildsquare stroke grestore /s 4 def gsave 5 0 translate 4 3 atan rotate newpath buildsquare stroke grestore % --- the vertical line ------------------------------------------------ % find the vertex (x, y) /x 3 5 div 3 mul def /y 4 5 div 3 mul def % and some analgous ratios /X 3 5 div 4 mul def /Y 4 5 div 4 mul def newpath x y moveto 0 y 5 add neg rlineto stroke % --- the red triangle ------------------------------------------------ newpath 0 0 moveto x y lineto 0 -5 lineto closepath gsave 1 0 0 setrgbcolor fill grestore stroke % --- the other triangles ------------------------------------------------ newpath 0 0 moveto y neg x lineto 5 0 lineto closepath stroke newpath 5 0 moveto 5 X add Y lineto 0 0 lineto closepath stroke newpath 5 0 moveto x y lineto 5 -5 lineto closepath stroke showpage