Lab 3: PostScript
6.005 Elements of Software Construction
Spring 2008
Due: Friday, March 14
In this lab, you will get a quick introduction to the PostScript language,
which you will be using in your project.
Before Lab
Before coming to lab, please do the following:
- Read both Project 3 and this lab handout.
-
Read through the sections of the guide
to PostScript listed below.
Install Ghostscript and Ghostview if you don't already have them. Ghostscript
is a "PostScript previewer" -- an interpreter for programs written in PostScript.
There are many interpreters available on a variety of
platforms. Here are the recommended ones:
- Windows: install Ghostscript 8.54
and GhostView 4.8.
- MacOS: the Preview application acts as a PostScript viewer
(by first translating from PostScript to PDF), but it does not report PostScript errors,
so you will probably want to install Ghostscript. One version that's easy to install is EPS Ghostscript.
- Athena: already installed.
- Linux: find the ghostscript package for your Linux distribution and install it, if you don't already
have it.
The Lab
Running your first PostScript programs
Ghostscript is an interpreter, which gives you a prompt and lets you type Postscript
code interactively and see its results. Ghostview is
file viewer, which runs a Postscript file and displays the resulting picture.
Start Ghostscript (on Athena/Linux/Mac, run the command gs). You should see a prompt. Type the following Postscript code:
2 3 add pstack
You should see it display 5. (The pstack command prints the current contents of the stack, which is useful for debugging.)
Now create a file called square.ps with the following contents, and open it in Ghostview (gv on Athena and Linux,
Preview on Mac):
newpath
1.5 setlinewidth
72 72 moveto
72 0 rlineto
0 72 rlineto
-72 0 rlineto
closepath
stroke
showpage
This program creates a 1-inch square located 1 inch above and 1 inch
to the right of the page's bottom left corner. (PostScript uses typographic units: 1 inch
is 72 "points").
Working through a PostScript tutorial
Work through this guide
to PostScript, focusing on the following sections:
The first five sections are contiguous, so you can go from
one to the other by starting at the first and just clicking "next page".
Do the following exercises:
Creating your own PostScript program
Write a PostScript program that draws a rough representation of MIT's dome (as shown, for example,
here). Your program should at least draw some columns
and a semicircle for the dome itself. We suggest that you sketch your design on paper first,
marking your intended dimensions. To draw a circle, you will need to use the arc command, described in the
tutorial
here.
Checkoff. Find a TA or another member of the course staff and
demonstrate your PostScript creations to be checked off on this lab.