lang/postscript/ BasicPostscript1


PostScript is a Forth-like language. That is, it is a stack-based, threaded-interpreted language.

Simple drawing can be accomplished as follows:

newpath
100 100 moveto
100 200 lineto 
200 200 lineto 
200 100 lineto 
3.14 setlinewidth
closepath stroke

We can store a list of words for later recall as follows:

/mysquare {
newpath
0 0 moveto
0 1 lineto
1 1 lineto
1 0 lineto
closepath
} def

/makepink { 1 0.5 0.5 setrgbcolor fill }
/makepurple { 0.7 0 0.7 setrgbcolor fill }
/makeorange { 1 0.7 0 setrgbcolor fill }
/makeblue { 0 0 1 setrgbcolor fill }

31 31 scale
10 10 translate mysquare makepink
0 5 translate mysquare makepurple
5 0 translate mysquare makeorange
0 -5 translate mysquare makeblue

We can draw text as follows:

/Palatino findfont
18 scalefont
setfont
100 50 translate
(Hello World) show

PostScript has a full set of basic graphics operations, which can be used as above. At this level, it is delightfully simple.