11.6. PostScript Examples   

The following code is from the PostScript Language Reference Manual 2nd Edition from Adobe Systems Incorporated, page 153.

It shows how images can be transformed easily by PostScript operators.

 %!

/box {newpath % Define a procedure to construct a unit square
0 0 moveto % path in the current user coordinate system,
0 1 lineto % with its lower-left corner at the origin.
1 1 lineto
1 0 lineto
closepath
} def
gsave % Save the current graphics state and create a
% new one that we shall then modify.
72 72 scale % Modify the current transformation matrix so
% everything subsequently drawn will be 72 times
% larger; that is, each unit will represent an
% inch instead of 1/72nd of an inch.
box fill % Draw a unit square with its lower-left corner
% at the origin and fill it with black. Because
% the unit size is now one inch, this box is
% one inch on a side.
2 2 translate % Change the transformation matrix again so
% the origin is at 2", 2" (displaced two inches
% in from the left and bottom edges of the
% page).
box fill % Draw the box again. This box has its lower-
% left corner two inches up from and two inches
% to the right of the lower-left corner of the
% page.
grestore % Restore the saved graphics state.
% Now we are back to default user space.

    
Output of example one
Fig. 11.2 : Output of example one
Output of example one.

Adding the following section of code before the grestore command in example one will demonstrate how to rotate objects.

 .

.
.
45 rotate % This sets up the transformation matrix for
% a 45 degree rotation.
0.5 2 translate % This moves the origin across 0.5", and up 2".
% (Remember the 45 degree rotation)
box fill % Draws another filled box.
.
.
.

    
Output of example two
Fig. 11.3 : Output of example two