![]() |
![]() | |||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
|
This is a tiny primer on very simple Postscript language. Just the bare bones, ignoring anything fancy. [1] Postscript is a programming language and it uses a stack. eg to add 3 and 5 use:
As the program executes, it reads 3 and pushes it on the stack, then pushes 5 on the stack. It reads 'add' which tells it to take 2 numbers off the stack, add them and push the result on the stack. [2] Set a variable to a value by defining it:
Both of these set the variable 'myvar' to 123 - the number at the top of the stack. [3] Comments
[4] Drawing a line:
'gsave' and 'grestore' save and restore the 'graphics state'. 'moveto' moves to an absolute point. 'rlineto' draws relatively to the last point. So here you draw from coordinates 30,30 to 40,10. [5] Filling a shape Draw the lines with 'rlineto' or 'lineto' and use 'fill' instead of 'stroke'. You may need to 'setgray' first. [6] procedures Define thus:
Call a procedure by simply quoting its name. Procedures often use the contents of the stack, eg
You push 4 on the stack and call 'add5'. This in turn pushes 5 on the stack, then calls 'add', which adds the top two numbers on the stack and leaves the result 9 on the stack - for you to do something with. [7] Conclusion Guess what - there's loads more to the Postscript language than this. This is just to give you a starter in case you want to play with an existing simple Postscript file. | ||||
|
page date: 12Nov04. I enjoy correspondence stimulated by this site. You can contact me here. | ||||
![]() |
![]() | |||