COS 426 Computer Graphics - Fall 1997

COS 426 Home

Projects

Project 0

Project 1 (hints)

Project 2 (hints)

Project 3 (hints)

Project 4 (hints)

Project 5 (hints)

Project 6

PostScript hints
(Part of this text was adapted from Appendix 1 of Computer Graphics by Francis Sandy Hill Jr.)

PostScript is a page description language that can be used to drive many graphics devices in use today. It is particularly effective for laser printers, many of which contain a microprocessor-based interpreter that can receive and translate PostScript commands into patterns of ink.
The default coordinate system places (0, 0) at the lower left corner of the page, with x increasing to the right and y increasing upward. One unit in this default space corresponds to 1/72th of an inch.
PostScript uses a "postfix" notation in which parameters precede the function. Hence to draw a line from the current position to the display position (124, 67), the string "124 67 lineto" would be sent to the PostScript device.
Suppose we have a 640x480 image and the printer uses standard 8 1/2 by 11 inch paper. We would like to print the image in landscape orientation, leaving 1/2 inch of horizontal margin and 1/2 inch of vertical margin, as shown in the picture below.



To do this, we have to setup a transformation that maps points on the screen coordinate system to the paper coordinate system. The first thing to do is to scale the coordinates in x by 1.125 (10 in = 720 pts, and 720 / 640 = 1.125). Accidentally, we have to scale the coordinates in y by the same factor (7 1/2 in = 540 pts, and 540 / 480 = 1.125). If the factors in x and y were different, we would have to scale both in x and y by the smaller factor, to avoid aspect ratio distortion. Then we have to rotate the coordinates by 90 degrees to print in landscape orientation, and translate the origin of the coordinate system to the lower right corner of the paper. All these transformations can be done with the following PostScript code.

576 36 translate
90 rotate
1.125 dup scale

Now, if we want to draw a line from (0, 0) to (639, 479), we have to write the following PostScript code.

0 0 moveto
639 479 lineto

Usually, a PostScript file begins with a header like

%!PS-Adobe-1.0

and finishes with

stroke
showpage

So the complete PostScript code would be:

%!PS-Adobe-1.0
576 36 translate
90 rotate
1.125 dup scale
0 0 moveto
639 479 lineto
stroke
showpage


To learn more about PostScript and how to print more complex shapes, you might want to take a look at PostScript Language: Tutorial and Cookbook by Adobe Systems Incorporated. There is also plenty of on-line information about PostScript.

Last update: Sun Nov 30 18:09:15 EST 1997