How to make pictures using postscript program (part 3) --------------Example Program 4---------------------------------------------- %!PS-Adobe-2.0 EPSF %%Title: A staircase %%BoundingBox: 0.0 0.0 550.0 800.0 /step {0 50 rmoveto 80 0 rlineto} def newpath 50 100 moveto step step step step step step stroke showpage ----------------------------------------------------------------------------- Instead of repeating the command many times, we can also use a for-loop. The command consists of three numbers, followed by some code, in braces {}, followed by the command word for. The three number mean: it starts counting with the first number, increments in each round by the second number, until the result is larger than the last number. In each round, it executes the code in braces once. 1 1 6 {step} for executes the step six times. --------------Example Program 5---------------------------------------------- %!PS-Adobe-2.0 EPSF %%Title: A staircase %%BoundingBox: 0.0 0.0 550.0 800.0 /step {0 50 rmoveto 80 0 rlineto} def newpath 50 100 moveto 1 1 6 {step} for stroke showpage --------------Example Program 6---------------------------------------------- %!PS-Adobe-2.0 EPSF %%Title: A grid %%BoundingBox: 0.0 0.0 550.0 800.0 50 50 translate 1 1 20 {newpath 0 0 moveto 0 200 lineto stroke 10 0 translate } for -200 0 translate 1 1 20 {newpath 0 0 moveto 200 0 lineto stroke 0 10 translate } for showpage ----------------------------------------------------------------------------- Here we had to move back the coordinate system by 200 (-200 0: moves 200 left) since we move it right by 10 in each of the 20 rounds of the for-loop. ----------------------------------------------------------------------------- Besides drawing line segments, we can also draw circles or arcs. The command arc has five numbers as arguments, the coordinates of the center, the radius, and the start and end angle. 100 200 50 0 270 arc draws a three-quarter circle around point 100 200 or radius 50 --------------Example Program 7---------------------------------------------- %!PS-Adobe-2.0 EPSF %%BoundingBox: 0.0 0.0 550.0 800.0 250 300 translate 1 1 36 {newpath 100 0 100 0 360 arc stroke 10 rotate} for showpage