%!PS % Draw a spiral of squares % Illustrates: for-loop, rotate, translate, scale. % Joseph O'Rourke 5 setlinewidth 1 0 0 setrgbcolor % Red /inch {72 mul} def % Set scale to draw in inches: 4.25 inch 5.5 inch translate % Too large! Cut by 1/4: 0.25 0.25 scale % Draw a 1x1 square, lower left corner at current origin % Use gsave/grestore to both stroke and fill /square { newpath 0 0 moveto 1 inch 0 lineto 1 inch 1 inch lineto 0 1 inch lineto closepath gsave 1 0 0 setrgbcolor % Red stroke grestore 0.75 0.75 0 setrgbcolor % Olive Green fill } def % Draw a total of n squares /n 24 def gsave % start incr end 1 1 n { % bind loop variable to x (always on top of stack): /x exch def square 30 rotate 0 x 10 mul translate 1.1 1.1 scale } for % Unscale etc.: back to default coordinate system. grestore % Circle the origin so we can see it 0 0 1 setrgbcolor % Blue newpath 0 0 20 0 360 arc stroke showpage