1. Practical Examples
Real-world PostScript code examples demonstrating common tasks and techniques.
2. Hello World
Your first PostScript program:
%!PS-Adobe-3.0
/Helvetica findfont 12 scalefont setfont
100 700 moveto
(Hello, PostScript!) show
showpage
3. Drawing Basic Shapes
3.1. Rectangle
newpath
100 100 moveto
200 0 rlineto
0 150 rlineto
-200 0 rlineto
closepath
0.5 setgray fill
3.2. Circle
newpath
200 200 50 0 360 arc
closepath
0 setgray stroke
3.3. Triangle
newpath
150 100 moveto
250 100 lineto
200 200 lineto
closepath
1 0 0 setrgbcolor fill
4. Text Examples
4.1. Centered Text
/Helvetica findfont 24 scalefont setfont
(PostScript) stringwidth pop 2 div
300 exch sub 400 moveto
(PostScript) show
4.2. Multiple Lines
/Helvetica findfont 12 scalefont setfont
100 700 moveto (Line 1) show
100 680 moveto (Line 2) show
100 660 moveto (Line 3) show
5. Color Examples
5.1. RGB Colors
% Red square
1 0 0 setrgbcolor
0 0 100 100 rectfill
% Green square
0 1 0 setrgbcolor
110 0 100 100 rectfill
% Blue square
0 0 1 setrgbcolor
220 0 100 100 rectfill
5.2. Grayscale Gradient
0 0.1 1 {
/gray exch def
gray setgray
gray 10 mul 0 10 100 rectfill
} for
6. Practical Techniques
gsave
300 400 translate
45 rotate
0 0 100 50 rectfill
grestore
6.2. Clipping
gsave
newpath 150 150 100 0 360 arc clip
% Draw within circular clip
0 0 300 300 rectfill
grestore
6.3. Reusable Procedures
/box { % x y width height => -
gsave
newpath
moveto
dup 0 rlineto
exch 0 exch rlineto
neg 0 rlineto
closepath stroke
grestore
} def
100 100 50 75 box
Table of contents