The Basics of Drawing an Image

5.4 The Basics of Drawing an Image

Objects drawn on the screen are described in PostScript by a path . The model you should have in mind here is a pen on a paper. You describe the path using a sequence of commands that move the pen about the page. Just as with a real pen, you can choose whether a line should be drawn between two points, or if the pen should just be move to a new location. Once a path is completed, you can be draw it, as in the pen analogy described above, or you can fill it with ink to get a solid, or shaded object.

A path is started with a newpath command, which clears any previous path and prepares the system to start a new path. After a new path has been started, you must set the current point to somewhere on the page. Otherwise, how would PostScript know where you wanted to start from? This is done with the moveto command, which takes x and y co-ordinates as its arguments.

Postscript has a variety of commands to move the pen. For example, you can describe lines, arcs of circles, and Bezier curves. The most common command you will use is lineto, which draws a line from the current point to a point specified as it argument, and resets the current point.

The stroke command draw the path you have described. Alternately, the fill command fills the path with the current level of gray.

As you draw more paths, each one starting with a newpath , the objects will be drawn on top of each other in the order that they are drawn. Thus it is important that you think about the order in which you want to draw your paths.

Next


David Maxwell, who is still writing this, would like to hear your comments and suggestions. And remember, parts of this manual are based on P.J. Weingartner's work: A First Guide to PostScript.