%!PS % Seed RNG, change the value to get different mountain % shapes 1234 srand % Rounded line joints 1 setlinejoin % Scale coordinate system so 1 unit is 36 "points" (half an inch) 36 36 scale % The image in drawn in a 10x10 unit square, with bottom left % corner at (1, 1) % Function drawblock % Stack setup: red, green, blue, height, linewidth % Draws a coloured block at the bottom of the image, with width equal % to the entire image, with the specified height. Gets a black outline % of specified width, and is filled with specified RGB colour. /drawblock { % Line settings setlinewidth 0 setgray % Draw path newpath 1 add % (1,1) coordinate offset 1 exch moveto 10 0 rlineto 11 1 lineto 1 1 lineto closepath % outline and fill gsave stroke grestore setrgbcolor fill } def % Function mountain % Stack setup: red, green, blue, height, linewidth % Draws a mountain which slopes downward from left to right. % Mountain begins at specified height. % With each 1 unit movement to the right, the mountain height randomly % changes. Large downward steps have probability 0.6, small upward steps % and flat sections each have probability 0.2. % There is no code to handle the mountain hitting the bottom of the image % frame before it hits the right hand boundary, so don't set the initial % height too low or the image will break with non-negligible probability. % Gets a black outline of specified width, and is filled with specified % RGB colour. /mountain { % Line settings setlinewidth 0 setgray % Drawn path newpath 1 add % (1,1) coordinate offset 1 exch moveto % 10 step loop 10 { % Get a random number, reduce it mod 5 rand 5 mod dup % Prepare for second comparison 3 lt { % If 0 <=r <= 2 1 -0.75 rlineto % Slope down pop % No second comparison } { 3 eq { % If r == 3 1 0 rlineto % No slope } { 1 0.5 rlineto % Slope up } ifelse } ifelse } repeat 11 1 lineto 1 1 lineto closepath % outline and fill gsave stroke grestore setrgbcolor fill } def % The actual image! % sky 0.721 0.964 0.980 10 0.1 drawblock % distant mountain 0.627 0.823 0.556 8 0.1 mountain % midground mountain 0.741 0.513 0.078 7 0.15 mountain % lake 0.290 0.258 0.560 4 0.15 drawblock % foreground mountain 0.266 0.462 0.196 6 0.2 mountain % orange sun 9 9 1 0 360 arc 1 0.5 0 setrgbcolor fill % Draw a thick frame around the whole image 0.25 setlinewidth 0 setgray newpath 1 1 moveto 10 0 rlineto 0 10 rlineto -10 0 rlineto closepath stroke showpage