I am coming to believe that the atmosphere at ITP is infectious. Every time I pass through there I come away with this bug to work on another project. I stopped by yesterday while I was in New York, ran into someone I had met at the spring show and had a good chat about the new games venture he and two fellow ITP alums have just started developing for the iPhone platform. I also finally introduced myself to Tom Igoe and did my best not to sound like an idiot. Also, also…I got a glimpse “under the hood” of the Wooden Mirror. While cleaning up my bookshelf I found a Computer Graphics magazine from 1999 which had Daniel Rozin and the Wooden Mirror on the cover. The inside blurb mentioned that it was being driven by a Macintosh Quadra. I was really curious if they really still had a Quadra running to power it or if it’s been upgraded to some type of embedded microcontroller in the past 9 years…well, it’s been upgraded, to a beige G3 tower.

Anyway, this time around after leaving ITP I wanted to play with Conway’s Game of Life. Although it’s been done many times before, I was looking to do it myself to practice working with arrays. Specifically, when working with images (and video) you can store the value for each pixel in a one-dimensional array by appending each row of pixels into one very long array. There is some math involved convert from x,y cordinates to the arrax index, but it’s nothing too difficult after you’ve done it once.

Back to Life (….back to reality?). Keeping track of all the cells in a Conway game of life in a one-dimensional array is very similar to working with video. It wasn’t too much trouble to work out by reading the rules and looking at other examples. I am far more interested in a 3D version of the game. This has also been done…but my challenge was to track all the cells for the 3D matrix in a one-dimensional array. The sheer number of values started to make my head swim when doing the mental math, but in hindsight it wasn’t much more complicated than working with 2D data.

So, in the end, the Game of Life isn’t the focus of this experiment as much as figuring out how to store 3D data in a one-dimensional array…which seems to be much faster than using a multi-dimensional array…but who knows…I never studied comp sci.

A link to the sketch is below, but for reference here is the math for converting between coordinates and the array index (sx,sy and sz are the respective sizes of the axes):

int coordsToIndex(int x, int y, int z){
//convert from coordinates to the array index
//use the plane first (z), then the row (y), then the column (x)
return z*sx*sy+y*sx+x;
}
int[] indexToCoords(int index) {
//convert the index to x,y,z values
int z = index/(sx*sy);
int y = (index%(sx*sy))/sx;
int x = (index%(sx*sy))%sx;
int[] coords = {x,y,z};
return coords;
}

Game of Life 3D

(Hint, use the up/down and left/right arrow keys to alter the minimum and maximum life rules, respectively)