Oct 13 2009

Cellular Automator Project- Design Notes

These are the design notes for Cellular Automator, which will probably be a slow burning long term project, with no immediate commercial utility. I’m a hobbyist game programmer, and have basically no experience in Cellular Automata research, so if I get terms wrong please excuse and correct me.


CA was started because another project I’m working on requires a top to bottom rewrite and I had no motivation to continue working on that just now. As tends to happen when I’m not actively working on something, I was browsing through various sites I have bookmarked, and ran across Chris Crawford’s description of Trinary Life. I wasn’t that interested in Cellular Automata, but there was a flash applet written by Chris DeLeon which implemented the Trinary Life rules so I checked it out. DeLeon’s applet was interesting, but other than refreshing my browser, I couldn’t find a way to clear the screen in order to try a new pattern. Additionally, after playing around a little I thought interesting interactions in Trinary Life might occur only on smaller grids, so I wanted to be able to resize the playing field.


The 3×3 pattern on the left for example, will reduce to a green field in 1 generation.

Since I was implementing a CA system to do Trinary Life, there seemed no reason to not also implement Conway’s Game of Life at the same time. Seeds is a variation on CGoL which I ran across while looking for the exact rules to CGoL.


I kept my work in an almost pure MVC framework (failing to do this is why I need to re-write or messily hack the other project). The model stores the grid and implements rules, and outputs to 2 viewer classes. One interesting note is that the interesting stuff (the universe grid with the cells on it), only took 23% of the code which went into the project (286 lines vs 955 for everything else as of v0.2).

The simulation uses a pretty normal game loop triggered by a timer which fires approximately every 100ms (Flash timers are notoriously inaccurate). Two passes through the grid are made, the first calculates the effect of whatever ruleset is implemented and stores the new cell values in a ‘temporary structure’. (The temporary structure is a permanently defined 2d array, however). The second pass copies the values out of the temporary structure back to the model. The second pass could probably be obviated by changing the assignment of the main grid to the temporary structure, but I decided against this because I was concerned that Flash’s garbage collector would not be able to keep up constantly disposing of and creating grids. An alternate method could flip flop which grid was considered the current generation, and which was considered the scratchpad. This would eliminate the copy step.

Input is picked up once per timer cycle by a function which checks flags on every Controller object, and then handles those controllers which have input to be given. This does mean that if you click to add pixels faster than 100ms between each click, my program will miss pixels. At least in theory. It hasn’t seemed to be a problem for me so far.

Rendering is straightforward using bitmapData.copyPixels from blue, green and red reference bitmapData objects to a canvas Bitmap. Offsets and cell sizes in pixels are calculated during resizing. The simulation starts with a 100×100 grid.

The majority of the size in the swf is the embedded font Arial, used in the resize window and to display the number of generations. Quite possibly, everyone on earth already has Arial and this was unnecessary. :)


None planned. Source code available on request, email me at the address found on the about tab.

Future versions

Plans for future version in rough order of priority:

  • Fix bugs as they are reported and as I get a chance. 
  • Add support for any MCell encoded ruleset
  • Increase performance of grid calculations
  • Add support for larger grids (scroll, pan, minimap)
  • Brush support for some patterns, such as the f-pentomino

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment