A 1D Cellular Automaton in Postscript
You can tell it's exam season. Instead of revising I decided to procrastinate by learning Postscript and reading Stephen Wolfram's new book.
A 1D cellular automaton was created using a Postscript program. This means that you can send the following text to a Postscript printer (or load it into Ghostview) and the image following it will appear.
%!
%%(C)Iain Murray <timewaste at iainmurray.net>, May 2002
/m 280 store /t [false true true false true false true false] store /X { d c 1
put newpath c 296 add r sub 600 r sub moveto 1 0 rlineto 0 1 rlineto -1 0
rlineto closepath fill } def /O { d c 0 put } def /r 0 store /d m 2 mul 5 add
array store d 0 [0 0 1 0 0] putinterval 0 1 m -1 add { clear r 2 mul 4 add -1 2
{ /c 2 -1 roll store t d c get 2 bitshift d c -1 add get 1 bitshift add d c -2
add get add get {X} {O} ifelse } for /c r 2 mul 5 add store O /c c 1 add store O
/r 1 r add store } for showpage
Download a bigger picture (in png format). You may need to scroll around as the top left is blank.
I should probably write more about how it works and provide the properly commented version, but I really shouldn't be faffing about with this right now. It will be possible to make the above code shorter.
I am grateful for the following Postscript resources:
