Wednesday, December 12, 2012


There is a recent book about a simple, simple program for the Commodore 64. The title of the book is the program itself, namely:
10 PRINT CHR$(205.5+RND(1));:GOTO 10
This program generates a maze-like structure by printing a series of randomly selected forward or back slashes (technically, slash-like characters from the computer's character graphic set.) When the screen is filled, the "maze" scrolls up two lines and keeps on drawing.

You can get a free e-copy of the book at (They also have links to purchase physical copies). The text was a collaboration and goes into the history of C=64 one liners, the culture of computers that booted into BASIC, the meaning of (pseudo-)randomness, the legacy of mazes and labyrinths, etc etc. ( also had a nice review)

It's an inspiring book! Using processing.js, I created a slight variant on their "mazewalker" program, a variant that sends a little circle to wander the maze thus created:

There are some interesting nuances in how the maze walker works... although the "slashes" act as the walls, the walker is always "over" a slash, in a sense... but if you know which direction it was last traveling (and what type of slash it's over) you know which way it be deflect, and implicitly which section of the hallway it was travelling in.

My code for that is big and geared at readability, but Processing creator Casey Reas tweeted this tiny Processing version, from this processing forum challenge:
void draw(){int x=frameCount%20*5;int c=int(random(2))*5;line(x+c,89,x+5-c,94);if(x==95)set(0,0,get(0,5,100,x));} 
The end result of that is this:

So clever! It's very true to the spirit and feel of the original, though it has to do more work because the C=64 would keep track of the cursor and move the screen automatically.

No comments:

Post a Comment