forked from: convolution_life
ConvolutionFilterでlifegame元ネタ:http://psyark.jp/?entry=20050922000927
// write as3 code here..
package {
/*ConvolutionFilterでlifegame元ネタ:http://psyark.jp/?entry=20050922000927*/
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.ConvolutionFilter;
import flash.filters.DisplacementMapFilter;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.utils.getTimer;
public class Life extends Sprite{
private var life:BitmapData;
private var step:ConvolutionFilter;
private var rule:Array;
private var mc:Sprite;
public function Life(){
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);
}
}
}
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);
mc = new Sprite;
addChild(mc);
}
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);
var tc:Number = Math.cos( getTimer() * .0002 );
var ts:Number = Math.sin( getTimer() * .0003 );
mc.graphics.clear();
mc.graphics.beginBitmapFill(life, new Matrix( tc * ts + 1, ts, -ts, tc * ts + 1, 0, 0 ), true, false );
mc.graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
mc.filters = [ new DisplacementMapFilter( life, null, 1, 1, tc * 100, tc * 100, "wrap", 0, 0 ) ];
}
}
}