Moon in Water
/**
* Copyright J.J ( http://wonderfl.net/user/J.J )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rjzV
*/
package {
import flash.filters.BlurFilter;
import flash.utils.setInterval;
import flash.display.BlendMode;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.events.Event;
import flash.filters.ConvolutionFilter;
import flash.geom.Matrix;
import flash.display.Shape;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var h:Number,w:Number;
private var mainbmp:BitmapData,bmpbuff:BitmapData,bmptmp:BitmapData
private var cf:ConvolutionFilter
private var rect:Rectangle
private var p:Point
private var circle:Shape
public function FlashTest() {
// write as3 code here..
w=stage.stageWidth,h=stage.stageHeight;
mainbmp=new BitmapData(w,h,false,0);
bmpbuff=mainbmp.clone();
stage.addChild(new Bitmap(mainbmp))
circle=new Shape;
circle.graphics.beginFill(0xffffff)
circle.graphics.drawCircle(0,0,40);
circle.x=circle.y=w/2
// stage.addChild(circle)
mainbmp.draw(circle,new Matrix(1,0,0,1,w/2,h/2));
var cmatrix:Array=[
.5,1,.5,
1 ,0, 1,
.5,1,.5
]
rect=mainbmp.rect;p=mainbmp.rect.topLeft
cf=new ConvolutionFilter(3,3,cmatrix,3);
addEventListener('enterFrame',loop);
setInterval(drawCircle,500)
}
private function drawCircle():void{
mainbmp.draw(circle,new Matrix(1,0,0,1,w/2,h/2));
}
private function loop(e:Event):void{
bmptmp=mainbmp.clone();
mainbmp.applyFilter(bmpbuff,rect,p,cf);
mainbmp.draw(bmptmp,null,null,BlendMode.DIFFERENCE);
bmptmp.dispose();
bmptmp=bmpbuff;
bmpbuff=mainbmp;
mainbmp=bmptmp;
}
}
}