Game of Life in Postscript
smashr writes "It never really occured to me that postscript could be used for something other than printing, until I came across this page. Evidently someone has written the classic 'Game of life' entirely in postscript. You can even send it to the printer and have it output every single iteration.. now that would be a fun prank."
Sad memories of being a nine year old loser are flooding my brain at the mere mention of "The Game of Life".
I find it impressive that a technology that's been around since 1985 is not only still usable, but it's used almost everywhere for printing and is also an extremely powerful language. If only more technology was created this way these days. Definitely a testament to the people who created postscript...
using namespace slashdot;
troll::post();
Didn't someone write a webserver in postscript?
:)
Anyway, most people know script it turing complete - this is hardly the greatest hack ever
But it's cool - i'm not being negative.
actually, there are versions off it were you can win. its the same as the normal game of life, but 2 players control 2 'species'. each turn they can either place or remove any field, and the one survives wins.
Ok, someone write an OS in it.
PS-HTTPD - a webserver in PostScript.
Marxism is the opiate of dumbasses
True. In fatc, it's a stack-oriented programming language (like Forth). When Apple released the original LaserWriter in the mid-80s, it was actually the most powerful *computer* they made at the time (next in line was the Mac Plus -- remember those?).
Time flies like an arrow. Fruit flies like a banana.
..THIS game of life.. I couldn't quite understand out how that was going to work as it got spewed out of a printer :)
"Hey! Unless this is a nude love-in, get the hell off my property!!"
That postscript document has just one page that is never finished -- what you see on the ghostview screen is the first page being drawn, forever. So if you go and send this to a printer, the job never finishes and the printer "hangs" until you cancel the print job on the printer.
If you like this sort of thing, check out the PostScript Fractals page. You can print out very detailed images from tiny PostScript files.
%!PS-Adobe-1.0 EPSF-10. % PS GoBan (c) 1996 by Laurent DemaillyD /f{fill}D/S{setgray}D .5 M 1 0 arc gsave f R .5 S s c M e c M e .3 M 270 360 arc s R}D 0 0 x 2 M 1 0 arc .9 .7 .5 setrgbcolor f s 0 S c c x{d
%%BoundingBox: 0 0 150 150 % *** http://www.demailly.com/~dl/go/ ***
/D{def} def/d{dup}D/e{exch}D/s{stroke}D/l{lineto}D/M{mul}
/R{grestore}D/m{moveto}D/z 9 D/c 15 D/x z c M D/p{42 sub d z mod 1 add e z idiv
1 add gsave 1 index c M 1 index c M c
c
c m d x l d c e m x e l}for s(BeJR\\IHP>=6U){p}forall 1 S(?TS[QcGZFOC){p}forall
I've never used it, but you're talking about PS-HTTPD.
Pretty cool, eh?
--
the strongest word is still the word "free"
In some contexts, the size of the file sent
to the printer is an important consideration.
Coding a page as the shortest computer
program that can generate the page is "the
best you can do". Of course, whether or not
dvips is generating the optimal program is
another issue entirely.
How about a PostScript ray tracer?
Since it's Turing-complete, technically you could port an x86 emulator to it, and boot Windows in Postscript. In practice, of course, it would be insanely slow, but on a fast enough machine you could play Doom or Quake. 60ppm printer -> 1 fps ;-)
Postscript isn't just used for printers, either. NeXT used Display Postscript for the GUI, so applications were truly WYSIWG: the printer and the screen were rendering precisely the same source! Apparently this was one of the NeXT features which was inherited by Mac OS X, in modified form: parts of the GUI use Display PDF in much the same way.
Another nice little postscript program can be found here
It's only about 10 lines long and creates a image with 2 bubbles and even reflections.
And if someone wants to learn Postscript:
A first Guide to Postscript
I wrote a program that substitutes occurances of one string with another one. You send it to the printer than laugh as everyone else's pages mysteriously have the word "this" replaced with "that". One time I loaded it on just before a friend printed his source code. He couldn't figure out for the life of him where his semicolons had gone! Ah... youth.
The best part is, the code stays resident until the printer is power cycled. This enables slightly more sinster uses for this sort of thing. One of my professors used to joke about using as program like this to change the numbers on his paycheck when it was being printed!
The code is still on my website near the bottom. It's called PSReplace.
As other people have pointed out, it's useful to have a fairly powerful language in a printer since it allows the printer to adapt the printed stuff to the paper size and so forth (no pun intended).
Another language that is very closely related is pdf; as I understand it, it's pretty much postscript with a few cludges on the side to make it run faster.
-WolfWithoutAClause
"Gravity is only a theory, not a fact!"It is a programming language (stack based, like forth), which is amazing for its primary purpose: printing.
But to call the language itself "extremely powerful" is an exaggeration. As a programming language it is quite primitive and incomprehensible, compared to more powerful languages such as C++, java, ML, yes even forth.
Well, I still do not know why you used Touring completness for your example... I assume you are just reading about it in school, eh? Anyhow, not only NeXT, but the old NEWS distributed windows systems proposed by SUN did infact used postscrip. I believe SGI also implemented a NEWS server... it was overshadowed by X. Although I believe both SGI and SUN did merge X and NEWS together in their display servers....
Ok, I am finally prompted to write this... please forgive me but I feel compelled to comment.
There are two other times when I came to the realization that the tech community was sometimes way lost beyond the boundaries of practicality in addition to this latest thing. Once upon touring MIT and seeing the amazing amount of intellect dedicated towards uber mundane pursuits such as remotely identifying the inventory of a coke machine, and another situation at Siggraph seeing tens of millions of dollars wasted on research projects that had a snowball's chance in hell of developing practical applications for the findings.
Now I can appreciate the pursuit of a tech solution to something that's of interest, and I understand that things like Star Wars in ASCII are projects borne of love, but at the same time, I wonder, do tech people every try to achieve both in the same breath? Yes, you can add an ant farm to your PC case. But if you ever wonder why the mainstream looks at tech types as total weirdos, it's because they love to use as an example, these weird manifestations of our ability, when we all know, these are more the exception than the rule. Or are they?
So my question is, aside from the arguments where someone draws a reasoned path explaining how a tennis shoe with voice recognition will change society, is anyone concerned about the image of the tech community and finding more realistic ways to demonstrate the creativity and resourcefulness of nerds?
- You can send the graphical data in a very compact form, vectors and compressed bitmaps (the Apple drivers could compress bitmaps in JPEG and would transmit a JPEG decompresser postscript program).
- You can transmit your own data format. Instead of transforming your data into "real" postscript, you send a set of postscript procedures that reproduce the behaviour of your graphic language. This was actually one of the primary requirements of postscript, something that could handle quickdraw (Apple's graphic language pre OS-X) reasonably well. DVI2PS does a similar trick.
- You can factorise out common data. For instance you could transmit a form once, and then only send the data to fill out multiple versions of the form.
- Pre-loading - you can upload common fonts to the printer, this saves you the time of including them in all jobs. Some high-end postscript printer even have hard drives to store those fonts.
- Precision handling - instead of calculating word justification on the computer, you send a procedure to calculate word positioning to the printer, this ensures that justification is done using the printer's font metrics and knowing the printer's resolution.
- Special handling and configuration. Special printer configuraton can be handled using postscript. For instance on certain printers, the user has to enter a PIN to trigger output. This is very usefull for sending sensitive documents to shared printers.
- On the fly reconfiguration - for instance you can reprogram the printer to do 2-up or 4-up printing quite easily.
This design made a lot of sense when postscript printers started, bandwidth to the printer was bad (serial, parrallel or localtalk) and processing power on the machines was low - in fact it was common to have a laserwriter II (68020) attached to a classic 9' macintosh (68000).Even nowadays this design makes sense for network attached shared printers - this ensures that page composition is not tied to the client machines. Also you have to realise the bitmap of printing page is quite large: an uncompressed A4 page 300 DPI black/white bitmap is around 15MB. Today's laser printer support 2400 DPI, that means nearly a Gigabyte per page.
I can't believe that tons of people asked why someone would write an HTML browser in Java, but hardly anyone asked why someone would do this?
:)
Are you guys living in the real world?
That's nothing! In college, my compiler writing course was changed (to help "discourage ``re-use'' of previous years students' code") to writing a C compiler which used *PostScript* as its target language instead of XYZ machine code for PDQ processor.
We took the output of our compiler and "ran" it with ghostscript. It was actually quite fun. One of the harder parts was writing a suitable "libc" to "link" in for basic stdio.
Woohoo! Now I can have that flip book story of evolution I've always wanted!
Install Ghostscript first, then use GSView to open the .ps files.
By the mid-90s, Xerox had written what was basically a SmallTalk interpreter using GhostScript. It was called DocuScript.
With that, Xerox wrote all sorts of applications for hallway copiers, including web browsers, hang-man games, and image processing/manipulation applications.
Take a piece of paper with an image you want to copy. Circle the image. Scan it. Take a piece of paper that you want the image on. Mark where the image goes. Scan the paper. Output: new piece of paper with the image from the first on it and the other elements from the second piece.
Ooops, you dropped 200 pages of a paper on the floor, and you have gathered it up in the wrong order. Circle the page number on the first page of the paper. Scan the entire paper in. Output: your paper now resorted according page number.
Go to a hospital and triage yourself by taking a printed image of the human body and circling on the image where you hurt and scanning it in to the hallway copier.
Take your 100 page paper and scan it into the hallway copier. Get a one page token in return (containing, basically, an encoded URL) Fly across country to a conference holding only that one page token. At the conference scan in your token. Output your 100 page paper.
And then, being Xerox, they found they couldn't/wouldn't/didn't want to sell it. Talk about the Game of Life!
Example? Turing completeness is pretty significant.
I assume you are just reading about it in school, eh?
Then you assume wrongly.
Anyhow, not only NeXT, but the old NEWS distributed windows systems proposed by SUN did infact used postscrip. I believe SGI also implemented a NEWS server... it was overshadowed by X. Although I believe both SGI and SUN did merge X and NEWS together in their display servers....
NeXT is the nearest to a mainstream example; while NeWS was derived from Postscript (predating Display Postscript), it was never a compliant Postscript implementation, ruling out the big screen<->printer WYSIWYG advantage. Irix 4 introduced Display Postscript support, used by Impressario, but NeWS was dropped after Irix 3.
The key difference is, IMO, NeWS was a dead-end, replaced entirely by X - NeXT's Display Postscript lives on, as Display PDF in Quartz.
Conway's Game of Life is also turing complete; therefore, you can regard this PostScript hack as proof that PostScript is turing complete as well, since you could implement a turing machine on top of Life, on top of PostScript..... :)
pb Reply or e-mail; don't vaguely moderate.
do you know anyone who has "finished" Tetris? Yet it is still a game.
(Context: debating an assertion that Conway's Game of Life has no end condition; therefore, it's not a game. wo1verin3 brings an analogy to Tetris brand games.)
do you know anyone who has "finished" Tetris?
Some falling tetramino games, including Tetris brand games, display fireworks and credits after the player has completed specific objectives. For example, in The New Tetris for N64, it's 500,000 lines summed over all games played.
Will I retire or break 10K?
who read the blurb and expected the printer to start printing out little cards reading "Teacher", "Doctor", "20,000", "100,000", etc? :)
The best source about PostScript as a programming language is book "Thinking in PostScript" (http://www.rightbrain.com/pages/books.html).
I read it originally to learn PostScript from a printing perspective, which was somewhat futile. Very little of the book actually talks about printing or page layout at all.
Anyhow, a quick read of the table of contents would be enough to understand that the Game of Life in PostScript is neither difficult nor terribly interesting.
c.
Log in or piss off.
The most valuable difference between PDF and Postcript is that page breaks are set in stone in PDF, which is not the case in PS. Thus, if you save your work in PS, it is possible sometimes to get a tiny amount of stuff hanging off onto the last page by itself due to subtle metrics differences between printer fonts and screen fonts, roundoff errors, etc. PDF prevents this.
java is a worthless joke, a play-pretend half attempt at platform independence. there is no such thing as a java binary. java is not compiled. it is an interpreted language that runs specially compressed source code. there is no virtual machine. JRE is a glorified GWBASIC platform. java is the worst thing to happen to programming in ages.
There is no such thing as bytecode. These "registers" are lies. There is no runtime stack. The javac executable is really a wrapper around gzip. This "JVM" is a fabrication concocted by the infidel authors of GWBASIC and does not exist. These cowards have no morals. I blame Al-Jazeera- they are marketing for Sun. God will roast their stomachs in hell. They are not in control of anything- they don't even control their own code! Be assured, our CPUs are safe and protected from compressed interpreted source code. We have placed their threads in a quagmire from which they can never emerge unless they throw an exception. Java is a snake and we will cut it in pieces!