Scientific Visualization Seminar and Workshop
PostScript Workshop Exercises

John Louie, 5 Feb. 1997

You can most easily complete these exercises in the Mackay School of Mines Mapping, Modeling, and Visualization (MMV) Lab, in LMR 286. If you would like instead to use the Seismology Sun workstation lab in LME 320, see the other version of this exercise. Wherever you complete this exercise, all the files we use are available via anonymous ftp from ( in the vis/pswork directory. You need a WWW viewer, text editor, and PostScript interpreter for the exercises. (If you have a Macintosh, you can download such packages from ``''; if you have a Windows PC, use ``'', or call the UNR System Computing Services Help Desk at (702) 784-HELP.)

On the Macs and the PCs in the MMV Lab, you will find links to the following programs on the desktop: ``Netscape 3.0'', the WWW viewer (make sure you are using Netscape Navigator version 3.0 or higher); ``Ghostview'', ``gsview'', or ``Mac GS Viewer'', the PostScript display application; and ``wordpad'' or ``BBEdit'', a text editor. Just double-click on a desktop icon to start a program.

1) Sit down at one of the seven Macs or PCs in the MMV Lab. Divide into small groups if there are more people than machines. Turn on the power to the monitor if it is off, by pushing the button just below the screen. Don't ever turn off the power to the computer.

2) Now let's start the Netscape World-Wide Web viewer application. Find the ``Netscape 3.0'' icon on the desktop and double-click on it. Once the viewer appears, find the ``Scientific Visualization Seminar and Workshop'' under the ``Bookmarks'' menu, and select it. Then click on the ``Postscript Workshop'' item in the seminar schedule on that page. If the bookmark is missing, click left on Netscape's ``Open'' button, and in the dialog box that appears enter ``'' and click ``Open''. Now you should be looking at this exercise.

3) Now display a simple PostScript file. First you need to obtain an example file. In your WWW viewer click on ``Open'' and type the location from which you can transfer the file:

If you are reading this from a WWW viewer, you can click on the blue underlined words to accomplish this. Netscape should say that it is ``Done'' or ``Will open with GSview'', and the GhostView PostScript viewer application should appear.

With some WWW viewers, files ending in ``.ps'' will be treated as unknown binary, and not start the PostScript viewer application. In that case, a dialog box appears that will allow you to save the ``'' file, and you can select the Desktop (Mac) or c:\windows\desktop (PC) directory, and click ``OK''. Then you can minimize or hide the Netscape window and drag the ``'' icon on the desktop over the ``GSview'' or ``Mac GS'' icon. In any case, within a few seconds GhostView will interpret the PostScript program and display the results. A dark box should appear at the lower left corner of the page. Drag the scroll bar at the edge of the window to move the page around until you can see the box.

4) To make changes to the program, close the GSview window and drag the PostScript file's icon over the BBEdit (Mac) or wordpad (PC) icon on the desktop. A text editing tool appears with the PostScript program in its window. Note in the PostScript code that the box is filled with the default color, black. Change that to light gray by adding a line ``0.8 setgray'' above the ``fill'' command. Just click at where you want to add text and type. Note that the different elements of a PostScipt program, pushed separately onto the execution stack, are distinguished by some kind of ``whitespace''. Make sure you leave a space, tab, or return between numbers and operators, for example. Now save your changes by selecting ``Save'' under the ``File'' menu in BBEdit or wordpad, and view the results of the changes by dragging the PostScript file's icon over the GSview icon again. You can also select ``Run'' from the GSview menus. Did you get the expected results? What gray value would you use for a dark gray? Note that on 256-color displays you may have to have the mouse pointer arrow on the display window for the colors to be correct.

5) See what happens when you make an error in PostScript syntax. In the BBEdit or wordpad editing window, cut out just the ``0.8'' in front of the ``setgray''. Drag the PostScript file's icon over the GSview icon again. Note that GSView prints a long message into an error or log window giving you the error condition encountered by the PostScript interpreter. Look up within that window for the ``stackunderflow'' message. These errors are defined in the ``Red Book'', the PostScript Language Reference manual.

6) Change the program to stroke a black line instead of fill. Cut out the ``setgray'' line and substitute ``stroke'' for ``fill''. Make the line fatter with a ``3 setlinewidth'' command above the ``stroke''. Make the line dashed with a ``[5 5] 0 setdash'' command above the ``stroke''.

7) Now make the box shaded AND stroked. Use the following between the ``closepath'' and ``showpage'' commands:

gsave 0.8 setgray fill grestore
3 setlinewidth [5 5] 0 setdash stroke
This sets a gray and fills first, then restores the previous graphics state (with black the default color, and still containing the box path) and strokes.

8) Experiment with color instead of gray fills. (Even if you are displaying on a monochrome screen, you should see differences in the gray level shown, in exactly the same way a black-and-white TV shows grays instead of the colors in the TV signal.) Use ``1 0 0 setrgbcolor'' instead of ``0.8 setgray''. What color is this? Try ``0 1 0'' and ``0 0 1'' in front of the ``setrgbcolor'' to see the other primary additive colors. The primary subtractive colors cyan, magenta, and yellow are ``0 1 1'', ``1 0 1'', and ``1 1 0'' respectively. What color is ``0.5 0.5 0''? Can you find a combination that makes pink? Purple?

9) Now let's move the box nearer the center of the page. Insert ``200 200 translate'' near the top of the file, just after the ``%!''. Then insert ``2.5 1.5 scale'' just below the translate. Then precede the scale by a ``31 rotate''. What happens if you put the rotate after the scale?

Since you are done with ``'' you can drag the file's icon to the trash. Please do not leave any files on the MMV machines at the end of the exercise. If you want to save your altered PostScript files, they will easily fit on a floppy.

10) Try a new PostScript file. Get the file located by ``'' by clicking here. (Save the file to the desktop if your WWW viewer does not start the PostScript viewer, and drag it over the GSview icon.) What is it? Now the file over BBEdit or wordpad to edit

11) Make the text about one inch high using two different methods. One would be with a ``scale'' command, the other by changing the ``scalefont'' command. Hint: there are 72 points per inch.

12) Move the text closer to the center of the page. There are also two separate ways to do that, with either the ``moveto'' or with a ``translate''. Now see what happens when you rotate the text by putting a ``-31 rotate'' command near the top, just below the ``%!''. Try rotating text moved with both the moveto and translate methods.

13) Change the text and font, or type style. Type in your own message. Try the fonts ``/Courier'', ``/Helvetica-Bold'', ``/Symbol'', or even ``/ZapfDingbats''. The capitalization, slashes, and dashes really matter in PostScript.

14) Get the file located by ``'' by clicking here. (Save the file to the desktop if your WWW viewer does not start the PostScript viewer, and drag it over the GSview icon.) This file demonstrates recursive calls to a procedure (calling itself). Thus a simple program can generate a very complex plot. The ``/maxdepth'' definition near the top controls the complexity. Try setting it to 1, 2, 3, and 6, observing the increasing complexity. Don't try to make it larger than 12 or so, as the interpreter will take a very long time to show it.

15) Get the file located by ``'' by clicking here. (Save the file to the desktop if your WWW viewer does not start the PostScript viewer, and drag it over the GSview icon.) Then follow the instructions we give here, and that are in comments within the file's PostScript code, to change and annotate this color image. First look at the top of the file and note the ``CHANGE THIS'' instructions. Use the ``Search'' functions of BBEdit or wordpad. Find more occurrences of ``CHANGE THIS''. Follow the instructions there to make the image smaller and center it on the page.

Note that the text annotation is independent of the image. Then search for ``Nutra'' to find the code describing the text annotation. Experiment with the text's size, location, font, color, and rotation until you have a pleasing label. Finally, search for ``color value'' to see where I added code to affect the image colors. Uncomment the three lines below. What happens to the image?

If you are ambitious, try to make the image brighter. Can you change the mix of colors, or plot a negative image? Hint: the RGB image values are single-byte integers per color, varying from 0 to 255. is a large file, over 100 kilobytes, so please trash it from the desktop (and Empty the Mac's trash) when you are done.

16) On a Mac only, you can try dragging a PostScript file over the icon of Adobe Illustrator version 6.0 or higher. Illustrator will interpret the file and allow you to graphically edit the objects described in the PostScript file. You can get further hints on what to do with PostScript files from the page on Web and Multimedia Development Software Available in the UNR Seismological Lab.

Return To UNRSL Homepage