CS 3723/3721
|
Here is a sample postscipt file, stored using the filename abc.ps:
%!PS-Adobe-2.0 /Times-Bold findfont 200 scalefont setfont 100 300 moveto (ABC) show showpage
% vi abc.ps -- create the file using some editor % ps2pdf abc.ps abc.pdf -- convert to PDF, produce error messages % lp -d tub abc.ps -- print on a Postscript printerOpen a link to this file as: .ps, or as .pdf
First Version | Second Version | Third Version | Fourth Version |
---|---|---|---|
%!PS-Adobe-2.0 newpath % black 252 324 moveto 0 72 rlineto 72 0 rlineto 0 -72 rlineto closepath fill newpath % dark 270 360 moveto 0 72 rlineto 72 0 rlineto 0 -72 rlineto closepath .4 setgray fill newpath % light 288 396 moveto 0 72 rlineto 72 0 rlineto 0 -72 rlineto closepath .8 setgray fill showpage % print |
%!PS-Adobe-2.0 % Define box proc /box { 72 0 rlineto 0 72 rlineto -72 0 rlineto closepath } def % Begin Program newpath % black 252 324 moveto box 0 setgray fill newpath % dark 270 360 moveto box .4 setgray fill newpath % light 288 396 moveto box .8 setgray fill showpage |
%!PS-Adobe-2.0 % Define procedures /inch {72 mul} def /box % stack: x y => --- { newpath moveto 1 inch 0 rlineto 0 1 inch rlineto -1 inch 0 rlineto closepath } def /fillbox % stack: gray => --- { setgray fill } def % Main Program 3.5 inch 4.5 inch box 0 fillbox 3.75 inch 5 inch box .4 fillbox 4 inch 5.5 inch box .8 fillbox showpage |
%!PS-Adobe-2.0 % Define procedures /inch {72 mul} def /box % stack: x y => --- { /y exch def % save /x exch def % save newpath x y moveto 1 inch 0 rlineto 0 1 inch rlineto -1 inch 0 rlineto closepath } def /fillbox % stack: gray => --- { setgray fill } def % Main Program 3.5 inch 4.5 inch box 0 fillbox 3.75 inch 5 inch box .4 fillbox 4 inch 5.5 inch box .8 fillbox showpage |
Result: box1.pdf | Result: box2.pdf | Result: box3.pdf | Result: box4.pdf |
Postscript Program |
---|
%!PS-Adobe-2.0 /width 25 def /outline { % print standard border on page /Times-Bold findfont 15 scalefont setfont newpath width width moveto 0 792 width 2 mul sub rlineto 612 width 2 mul sub 0 rlineto 0 -792 width 2 mul add rlineto closepath stroke 275 width 5 add moveto (Bottom of Page) show 275 792 width sub 15 sub moveto (Top of Page) show } def /coord { /Times-Bold findfont 50 scalefont setfont 20 20 moveto (1) show -50 20 moveto (2) show -50 -50 moveto (3) show 20 -50 moveto (4) show 3 setlinewidth newpath 0 60 moveto 0 -60 lineto stroke newpath 60 0 moveto -60 0 lineto stroke } def outline %%%%%%% only change what comes after this comment %%%%%% 200 200 translate coord showpage |
Result in: .ps, or as .pdf |
Now keeping the same functions outline and coords, try some different instructions at the end and see what happens. In each case try to guess what the result will be first and then see what the result is. (I am leaving off the definition of the function and leaving off the final showpage.)
Substitute for red code | Result |
---|---|
200 200 translate rotate 90 coord | .ps, or as .pdf |
rotate 90 200 200 translate coord | .ps, or as .pdf |
90 rotate 200 -200 translate -90 rotate coord | .ps, or as .pdf |
200 200 translate 90 rotate 2 2 scale coord | .ps, or as .pdf |
2 2 scale 200 200 translate 90 rotate coord | .ps, or as .pdf |
1 1 30 { pop % throw away loop variable 300 150 translate 45 rotate coord 0.75 0.75 scale } for % just loops 30 times | .ps, or as .pdf |
Postscript Program |
---|
%!PS-Adobe-2.0 /path { % path is the outline of the chars ABC /Times-Bold findfont 200 scalefont setfont newpath 0 0 moveto (ABC) false charpath } def /oneline { % draw one line from the origin 0 0 moveto 450 0 lineto stroke } def /lines { % draw 180 lines at 1 degree rotations 180 {1 rotate oneline} repeat } def 100 300 translate % up to middle of page 3 setlinewidth % thick lines path stroke % outline the characters 1 setlinewidth % thin lines path clip % clip to inside of charactes 180 0 translate % to middle of string lines % draw the lines inside the string showpage % actually render the page |
Result in: abc3.ps, or as abc3.pdf |