How to make pictures using postscript program (part 1) Postscript is a programming language which is especially tailored to creating figures. On the computer, you can execute a postscript program by ghostview, gv or ggv; that then displays the result of your program. Or you can send it to your printer; many laserprinters understand postscript, and print the result of your program. Postscript files usually are given a name that ends in .ps or .eps ----------------------------------------------------------------------------- The first line of your postscript program must tell the computer that the following text is a postscript program. Use the first line %!PS-Adobe-2.0 EPSF (some variants are possible, depending on the version variant) Then it is usual to give some comment lines to describe the content, but they may be omitted. ----------------------------------------------------------------------------- The postscript figure itself consists of paths, which can be drawn. A path starts with the command newpath then you set the starting point with command moveto, as in 100 100 moveto you add further components to the path by the command lineto, as in 200 100 lineto this connects the previous current point to the point 200 100 by a line, and sets 200 100 to be the new current point. You can have many lineto commands in the same path. If you are finished with the path, you can use the command stroke to draw the path. newpath 100 100 moveto 200 100 lineto 200 200 lineto 300 200 lineto 300 300 lineto 400 300 lineto stroke draws a staircase with three steps. ----------------------------------------------------------------------------- The coordinate system is such that at the start the point 0 0 is in the lower left corner. In a letter-sized paper, the lower right corner is approximately 550 0, the upper left corner is approximately 0 800. First coordinate coes right, second coordinate goes up. In postscript, the coordinates are always put before the command. ----------------------------------------------------------------------------- You can move the coordinate system around, by the command translate. 300 400 translate moves the point 0 0 from the lower left corner 300 units to the right, and 400 units up, so approximately in the middle of the letter-sized page. ----------------------------------------------------------------------------- newpath 100 100 moveto 100 200 lineto 200 200 lineto stroke 0 200 translate newpath 100 100 moveto 100 200 lineto 200 200 lineto stroke draws a corner with vertices 100 100, 100 200, 200 200, and the another corner 200 units further up. ----------------------------------------------------------------------------- Instead of writing this path again, you can assign it a name, and the just use the name. the command def takes a name, prefixed by a slash (/) and any other text, enclosed in braces; and whenever the name is encountered again, it is replaced with the text. /corner {newpath 100 100 moveto 100 200 lineto 200 200 lineto stroke} def corner 0 200 translate corner has the same effect as the code before. ----------------------------------------------------------------------------- You can also have more complicated commands in the def. /cross { newpath -20 0 moveto 20 0 lineto stroke newpath 0 -20 moveto 0 20 lineto stroke } def