Creating Basic Grapics With Postscript (1 of 2)
Getting started with creating graphics in postscript is fairly simple. For this tutorial, a text editor will be used to write postscript (notepad is sufficient). GSview will also be used to view our files.

Paths and Line Drawing
Now that we have completed a "Hello World!" program in postscript using strings and fonts, lets draw "HELLO" to the page using postscript graphics.

First, here the new commands we will be using and their functionality:
Command Function
newpath starts a new path for graphical interaction
closepath makes a path line from the curent location to the end of the closest line
moveto allows moving to another location on the page without drawing a path line.
lineto draws a path line from current position on page to the location specified
stroke draws a visible line on the page wherever path line have been drawn
We will be using the following procedures. They are similar to the inch procedure you saw in Tutorial 1. 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
Be sure you put %! at the top of the document so it will be recognized as postscript.

Next, copy the following code into your document:
newpath % Start a new path

% H
1 m30 5 m60 moveto % 30px in from left and 5(72)px from bottom
1 m30 3 m60 lineto % draw a line down 2(72)px
1 m30 4 m60 moveto % move up 72px
3 m30 4 m60 lineto % draw a line right 2(30)px
3 m30 5 m60 moveto % move up 72px
3 m30 3 m60 lineto % draw a line down 2(72)px

% E
6 m30 5 m60 moveto
4 m30 5 m60 lineto
4 m30 3 m60 lineto
6 m30 3 m60 lineto
4 m30 4 m60 moveto
6 m30 4 m60 lineto

% L
7 m30 5 m60 moveto
7 m30 3 m60 lineto
9 m30 3 m60 lineto

% L


% O


stroke % Draw HEL on the paper

showpage

Following the format of this code, lets finish drawing the L and O.

First, the L. The easiest way to start is to copy the code from the first L and modify it. Using this method,
our y coordinates will stay the same. We just need to modify the x coordinates as follows:

We will change our moveto x coordinate and the first lineto x coordinate to 10 m30. Then change the second line to coordinate to 12 m30.

Save your file as hello.ps and open it with GSView to be sure everything is working.

Now add the O testing out your code to see if it works in GSView.

Problems:

  1. Decsribe what is happening in hello.ps using comments for each uncommented line.
  2. Draw a simple polygon (n-sided) using the commands above and a procedure you create.
The PostScript Tutorial Concieved and Created by Dann Ormond & Will Munn. Inspired by Mike Grady PhD. Website Design by NiftySites.com.