convolution_life
ConvolutionFilterでlifegame
元ネタ:http://psyark.jp/?entry=20050922000927
// write as3 code here..
package {
/*
ConvolutionFilterでlifegame
元ネタ:http://psyark.jp/?entry=20050922000927
*/
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.ConvolutionFilter;
import flash.geom.Point;
public class convolutionLife extends Sprite
{
private var life:BitmapData;
private var step:ConvolutionFilter;
private var rule:Array;
public function convolutionLife()
{
life = new BitmapData(465, 465, false, 0);
for(var i:int=0;i<465;i++){
for(var j:int=0;j<465;j++){
if(Math.random()*2>1){
life.setPixel(i,j,0xff00);
}
}
}
addChild(new Bitmap(life));
step = new ConvolutionFilter(3, 3, [1, 1, 1,
1, 9, 1,
1, 1, 1], 0xFF, 0);
rule = [0, 0, 0, 0x00FF00,
0, 0, 0, 0,
0, 0, 0, 0x00FF00, 0x00FF00];//13
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private const pt:Point = new Point();
private function onEnterFrame(e:Event) :void{
life.applyFilter(life, life.rect, pt, step);
life.paletteMap(life, life.rect, pt, null, rule, null, null);
}
}
}