/* * HODGEPODGE MACHINE * * Draws a Hodge-Podge machine. This a 2D Cellular Automata that mimics chemical reactions. It will eventually start to create spirals that overtake the screen. Each cell (pixel) can have different states, which go from healthy thru various stages of being infected to ill. Depending on the health of each neighbor each cell's new health is determined. * * 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 300x300 FLA, and put 'HodgePodgeMachine' (without quotes) as its Document Class. Test Movie et voila! * * @author Edwin Heijmen * @version 0.1 * * @see http://64.233.183.104/search?q=cache:faUhkErVcdEJ:www.scs.fsu.edu/~burkardt/fsu/poster.doc+hodgepodge+machine&hl=nl&gl=nl&ct=clnk&cd=10&client=firefox-a */ package { import flash.display.*; import flash.events.*; import flash.utils.Timer; public class HodgePodgeMachine extends MovieClip { private var states:Array = new Array(); // keep track previous and current states for each pixel private var w:uint = 300; // width private var h:uint = 300; // height private var tggl:uint = 0; // toggle between current and previous states private var m:uint = 127; // number of states // Hodge-Podge settings private var n:uint = 31; private var g:uint = 5; private var k1:uint = 2; private var k2:uint = 2; // used for displaying purposes private var bmd:BitmapData; private var bm:Bitmap; public function HodgePodgeMachine () { // constructor // // fill states array, once for current and once for previous states[0] = new Array(); // state previous states[1] = new Array(); // state current for (var i:uint=0;i0&&ne0&&ne0&&ne0&&ne0&&ne0&&ne0&&ne0&&ne0) { nS = Math.floor(sum/inf)+g; if (nS>n) nS = n; if (nS==pState) nS = 0; } else { nS = Math.floor(inf/k1)+Math.floor(ill/k2); } } // store new state & draw pixel cS[i][j] = nS; nS *= 8; bmd.setPixel(i,j,nS<<16); } } // update tggl tggl = 1-tggl; } } }