/* * GAME OF LIFE * * Conway's Game Of Life is not a game, but probably the most famous/well-known example of Cellular Automata. It is a simulation of Artificial Life where each cell in a grid can be either dead or alive and these states can switch on each generation based on a couple of simple rules. Also see the links below. * * To recreate, you'll need to have the Flash9 ActionScript3 preview installed, you can get it at http://labs.adobe.com/technologies/flash9as3tggliew/ * Create a new 400x400 FLA, and put 'GameOfLife' (without quotes) as its Document Class. Test Movie et voila! * * @author Edwin Heijmen * @version 0.1 * * @see http://en.wikipedia.org/wiki/Conway's_Game_of_Life */ package { import flash.display.*; import flash.events.*; import flash.utils.Timer; public class GameOfLife extends MovieClip { private var states:Array = new Array(); // keep track of previous and current states private var w:uint = 400; // width private var h:uint = 400; // height private var rnd:Number = 0.15; // random chance of a live cell at start private var tggl:uint = 0; // toggle between current and previous states private var alive:Number = 0xFF0000; private var dead:Number = 0xFFFFFF; // used for displaying purposes private var bmd:BitmapData; private var bm:Bitmap; public function GameOfLife () { // constructor // // fill states array, once for current and once for previous states[0] = new Array(); // previous states[1] = new Array(); // current for (var i:uint=0;i