Master Baboon The sea of the simulation


2D Cellular Automata

I decided to get my feet wet with Flash + ActionScript programming with a classic of the 80's: 2-dimensional Cellular Automata!

A 2D CA is a grid of cells, each of which can be in either an "alive" or "dead" state. The state of each cell evolves in time, according to simple update rules based on the number of alive neighbors (each cell has 9 neighbors). Briefly:

  • The update rule defines the overall behavior of the CA, and is given by two lists of numbers, S for "Survival" and B for "Birth"
  • If the cell is alive and the number of active neighbors is not on the S list, the cell dies
  • If the cell is dead and the number of active neighbors is on the B list, the cell becomes alive

The standard notation for the rules is S/B. For example, 23/3 (S=[2,3], B=[3]) corresponds to the celebrated Game of Life by Conway, that produces ever-changing patterns of activity. The reason CAs are so famous is because they are a perfect example of how simple, local rules can produce complex, global behavior.

In the Flash application below, you can experiment with different rules by (un)checking the checkbox on the right side. This wikipedia page has a list of rules known to produce interesting behavior.

Get Adobe Flash player

Short instructions: click on the grid elements to switch them between dead and alive states. On the right side, you can add numbers to the Survival and Birth list, clear the CA to a blank state, or set the cells to a random state.

Actionscript notes

You can download the AS3 and the Flash library here. This is my first ActionScript project, so everything was new to me. The hardest part for me was to figure out how to link the interface I designed in the Flash IDE with the AS3 classes. I think I found a decent solution in the end, but let me know if you have suggestion to improve the code.

The BinaryCA class is an independent class to manage 2D CAs. To store the CA cells I based the core on the Array2 class from polygonal labs' AS3DS data structures library.

Cellular Automata...  so retro!