Scientific Visualization Seminar and Workshop
PostScript Workshop Exercises

John Louie, 7 Feb. 1996

You can most easily complete these exercises in the Seismology Sun workstation lab, LME 320. However, all the files we use are available via anonymous ftp from quake.seismo.unr.edu (134.197.33.40) 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 ``ftp://quake.seismo.unr.edu/pub/mac/''. If you have a Windows PC, please contact the instructor, or call the UNR System Computing Services Help Desk at (702) 784-HELP.)

If you are completing this workshop on a Seismology Macintosh, you will find the following programs under the commands (Apple) menu: ``Netscape'', the WWW viewer; ``GhostScript'' or ``Mac GS Viewer'', the PostScript display application; and ``BBEdit'', a text editor. There will be some variations from the instructions below.


1) Sit down at one of the Sun workstations in the Sun lab. Divide into small groups if there are more people than machines.

2) Everyone who wrote their name down at the beginning of the class has a login name on these machines. If you do not have any other UNR computer account, your login is your initials (all small letters) followed by ``702h'', and your password is the default that I have told you. For example, John N. Louie would be ``jl702h''. If you have an active account at UNR, your login name here is the same, but with the default password I will tell you. Log in. If you see a query during the login process asking which window system you want, respond by typing ``o'' (small oh) for OpenWindows, and hit the Return key.

3) Now for some windows manipulation. To type in a window, you will have to point the mouse at it and click the left button. To bring a window to the front, click on its header or title bar with the left mouse button (click left). Note the menus associated with the background screen. Point to the background and hold down the right mouse button to see the ``Workspace'' menu. Keep holding the button down and drag over the ``Programs'' item until ``Command Tool...'' is highlighted. Release the button, and a command input window will appear. (To type in a window just by pointing at it, select ``Properties...'' from the ``Workspace'' menu, and finding the ``Miscellaneous'' panel from the ``Category'' menu button.)

4) If you have the default password, you must change your password. Move to the command tool window, and use the ``passwd'' command. Please create a new password that cannot be found in any dictionary, and contains numbers and punctuation as well as letters.

5) Now let's start the Netscape World-Wide Web viewer application. In the command tool window, type the ``netscape &'' command. After several seconds the viewer window should appear. If for some reason it doesn't work, or you see error messages, try a ``mosaic &'' command. Mosaic is another, less pretty WWW viewer. Once the viewer appears, click left on its ``Open'' button. In the dialog box that appears, enter ``http://www.seismo.unr.edu/ftp/vis/pswork/exercise.html'' and click ``Open''. Now you should be looking at this exercise.

6) 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:

`` http://www.seismo.unr.edu/ftp/vis/pswork/box.ps''.
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 pageview'', and the PageView 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 ``box.ps'' file in your home directory, and you can click ``OK''. Then go back to your command tool window and type ``pageview box.ps &''. In any case, within a few seconds PageView will interpret the PostScript program and display the results. A dark box should appear at the lower left corner of the page. Click and drag within the display window with the left mouse button to move the page around until you can see the box.

If you are using a Mac, let Netscape save the PostScript file (on the Desktop if you have a choice; otherwise it will be loose in the hard disk), and then go to the Apple menu to start the GhostScript application if necessary, and ``Open'' or ``Run'' the file manually from the GhostScript menu bar. Once GhostScript is running, it may come up automatically as it should.

7) To make changes to the box.ps program, click on PageView's ``Edit'' button. A text editing tool appears with the PostScript program in the upper window, and any error messages from the PostScript interpreter below. 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 (typing gets inserted, and delete affects in back of the cursor). Now render the change you made with the ``Run'' button above. Did you get the expected results? What gray value would you use for a dark gray? Note that you may have to have the mouse pointer arrow on the display window for the colors to be correct. If you lose the editing window, just select PageView's ``Edit'' button again.

With a Mac, you have to close the graphics window that came up, start the ``BBEdit'' or ``SimpleText'' application and open the PostScript file to alter the code, save the changes, and switch back to the GhostScript viewer to ``Run'' the PostScript file again.

8) See what happens when you make an error in PostScript syntax. In PageView's editing window, cut out just the ``0.8'' in front of the ``setgray''. Select ``Run''. Note that PageView prints a long message in the lower 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.

9) Change the box.ps 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''.

10) 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.

11) 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?

12) 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?

If you want to save your altered PostScript program, point at PageView's editing window and hold down the right mouse button to see the ``Text Pane'' menu, and select ``File->Store as New File...''. Then you can type a new file name into the popup window and click ``Store as New File''. (This is not necessary if you have been editing ``box.ps'' on a Mac.) Since you are done with ``box.ps'' you can point at the PageView window's title bar at the top and hold down the right mouse button to select ``Quit'' from the ``Window'' menu.

13) Try a new PostScript file. Get the file located by ``http://www.seismo.unr.edu/ftp/vis/pswork/text.ps'' by clicking here. (Save the file to your home directory if your WWW viewer does not start the PostScript viewer, and give a ``pageview text.ps &'' instruction in your Command Tool window.) What is it? Now select PageView's ``Edit'' button to edit text.ps.

14) 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.

15) 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.

16) Change the text and font, or type style. Type in your own message. Try the fonts ``/Courier'' and ``/Helvetica-Bold''.

17) Get the file located by ``http://www.seismo.unr.edu/ftp/vis/pswork/fractal.ps'' by clicking here. (Save the file to your home directory if your WWW viewer does not start the PostScript viewer, and give a ``pageview fractal.ps &'' instruction in your Command Tool window.) 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.

18) Get the file located by ``http://www.seismo.unr.edu/ftp/vis/pswork/nutra.ps'' by clicking here. (Save the file to your home directory if your WWW viewer does not start the PostScript viewer, and give a ``pageview nutra.ps &'' instruction in your Command Tool window.) Then follow the instructions we give and that are in the file to change and annotate this color image. First look at the top of the file and note the ``CHANGE THIS'' instructions. Point at PageView's editing window and hold down the right mouse button to see the ``Text Pane'' menu, and select ``Find->Find and Replace...''. Click left on the ``pushpin'' at the top left of the ``Text:Find and Replace'' frame if you want it to not disappear after your find operation. 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.

Nutra.ps is a large file, over 100 kilobytes, so please delete it and your temporary files (use the ``ls'' command in your Command Tool to list them, then the ``rm'' command to remove) when you are done. (On a Mac, open the hard disk if neccessary and drag the PostScript files from there or the DeskTop to the Trash. Then choose ``Empty Trash'' from the ``Special'' menu.)

19) Use the background menu under the right mouse button to find the ``Exit..'' command, and then type ``logout''. (With a Seismo Mac in LME 320, choose ``Go To At Ease'' from the bottom of the ``File'' menu.)

Return To UNRSL Homepage