GameOfLife
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);
});
}
}
}