Creating Basic Grapics With Postscript (2 of 2)
In this second part of the basic graphics tutorial, we will be discussing colors and filling paths. For this tutorial, a text editor will be used to write postscript (notepad is sufficient). GSview will also be used to view our files.

Colors and Path Filling
Now that we know how to create a path and stroke its edges with a line, lets take a look at some more interesting things.

First, here the new commands we will be using and their functionality:
Command Function
fill fills the area enclosed in the current path
setrgbcolor takes three numbers and converts them into an rbg color that will apply to any fill or stroke commands
setgray sets the level of gray that is applied to and fill or stroke commands
We will be using the following procedures. Copy and paste them into your text editor.
/m60 {60 mul} def %Convert m60->points (60/1 points) to use as an increment for movement
/m30 {30 mul} def %Convert m30->points (30/1 points) to use as an increment for movement
/m10 {10 mul} def %Convert m10->points (10/1 pixels) to use as an increment
Next, copy the following code into your document:
%Outline for 3d H
1 m30 2 m60 moveto
4 m10 2 m60 lineto
4 m10 65 lineto
8 m10 65 lineto
8 m10 2 m60 lineto
3 m30 2 m60 lineto
3 m30 0 lineto
8 m10 0 lineto
8 m10 55 lineto
4 m10 55 lineto
4 m10 0 lineto
1 m30 0 lineto
1 m30 2 m60 lineto


%Fill 3d H

%Add depth to 3d H


Save your file as and view it in GSView.

Lets add some color:

Copy the path for the outline of the H and paste it under '%Fill 3d H'.

Replace the 'stroke' command with the 'fill' command.

On the line before 'fill', we need to set the color. Use the following code:

1.0 .5 0 setrgbcolor
The numbers represent the Red Green and Blue levels of the color, respectivly.
1.0 is equivalent to full color.
0 is equivalent to no color.

Play with these settings and check them out in GSView.

Now add the three dimensional depth:

We will make the representaion of the depth gray in color, so use the following code:
.5 setgray
The number repersents the level of gray, 1 being black and 0 being white.

We will create and fill multiple paths to display our 3d representation. Here is the first:
1 m30 2 m60 moveto
4 m10 125 lineto
5 m10 125 lineto
4 m10 2 m60 lineto
1 m30 2 m60 lineto
When writing this program I found it easiest to draw the representation on a grid on paper first. Then I coded it in postscript.


  1. Finish creating the 3d H.
  2. Try filling your path from Tutorial 2 ( and see what happens. Can you explain this behavior?
The PostScript Tutorial Concieved and Created by Dann Ormond & Will Munn. Inspired by Mike Grady PhD. Website Design by