In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

GameOfLife

Get Adobe Flash player
by psyark 02 Jan 2009
    Embed
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.ConvolutionFilter;
	
	[SWF(width=465,height=465,frameRate=120,backgroundColor=0x000000)]
	public class GameOfLife extends Sprite {
		private var field:BitmapData = new BitmapData(465, 465, false, 0);
		private var step:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 9, 1, 1, 1, 1], 0xFF, 0);
		private var rule:Array = [0, 0, 0, 0x00FF00, 0, 0, 0, 0, 0, 0, 0, 0x00FF00, 0x00FF00];
		
		public function GameOfLife() {
			for each (var cell:Array in [[1,0], [3,1], [0,2], [1,2], [4,2], [5,2], [6,2]]) {
				field.setPixel((field.width >> 1) + cell[0], (field.height >> 1) + cell[1], 0x00FF00);
			}
			addChild(new Bitmap(field));
			addEventListener(Event.ENTER_FRAME, function (event:Event):void {
				field.applyFilter(field, field.rect, field.rect.topLeft, step);
				field.paletteMap(field, field.rect, field.rect.topLeft, null, rule, null, null);
			});
		}
	}
}