/* * MULTICOLORED CELLULAR AUTOMATA * * Draws a multi-colored one-dimensional Cellular Automata. Each cell can have a range of different states based on its previous state and that of its neighbors, all from the previous generation. * * To recreate, you'll need to have the Flash9 ActionScript3 preview installed, you can get it at http://labs.adobe.com/technologies/flash9as3preview/ * Create a new 600x300 FLA, and put 'MultiColoredCA' (without quotes) as its Document Class. Test Movie et voila! * * @author Edwin Heijmen * @version 0.1 * * @see http://www.wolframscience.org/ */ package { import flash.display.*; import flash.events.*; import flash.geom.*; import flash.utils.Timer; public class MultiColoredCA extends MovieClip { private var states:Array; // keeps track of states of cells on last-drawn line private var w:uint = 600; // width private var h:uint = 300; // height private var row:Number = 1; // keeps track of which row to draw private var rect:Rectangle; // used to copy from previous genereation to current generation private var p:Point; // used as referencepoint to copy previous generation to // settings for determining state private var num:uint = 64; // number of states private var num4:Number = num/4; // gets added to sum of neighboring states of previous generation private var fact:Number = 256/num; // factor to distribute num states evenly across 256 possible colors // used for displaying purposes private var bmd:BitmapData; private var bm:Bitmap; public function MultiColoredCA () { // constructor // // fill states array states = new Array(); for (var i:uint=0;i0)?(states[j-1]):(states[w-1]); c2 = states[j]; c3 = (j