package {
import flash.events.MouseEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
addChild(new Bitmap(_canvas));
_ripples.add(new Ripple(200, 200, 2));
stage.addEventListener(MouseEvent.MOUSE_DOWN, mD);
}
private function mD(e:MouseEvent):void {
_ripples.add(new Ripple(stage.mouseX, stage.mouseY, Math.random()*8));
}
private var _canvas:BitmapData = new BitmapData(465,465, false, 0x000000);
private var _ripples:RippleHandler = new RippleHandler(stage, _canvas);
}
}
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Stage;
class Ripple {
public function Ripple(X:int, Y:int, V:Number):void {
x = X;
y = Y;
v = V;
rad = 0;
}
public var x:int;
public var y:int;
public var rad:Number;
public var v:Number;
}
class RippleHandler {
public function RippleHandler(stage:Stage, bmd:BitmapData):void {
_canvas = bmd;
stage.addEventListener(Event.ENTER_FRAME, update);
}
private var _ripples:Array = [];
private var _canvas:BitmapData;
public function add(r:Ripple):void {
_ripples.push(r);
}
private var bf:BlurFilter = new BlurFilter(4,4,2);
private var cmf:ColorMatrixFilter = new ColorMatrixFilter(
[1,0,0,0,0,
0,1,0,0,0,
0,0,1,0,0,
0,0,0,.95,0]
);
private function update(e:Event):void {
for each (var r:Ripple in _ripples) {
r.rad += r.v;
if(r.rad>600)
_ripples.splice(_ripples.indexOf(r),1);
var n:Number = r.rad*6.28;
var angle:Number = 0;
var dA:Number = 2*Math.PI/n;
for(var i:int = 0; i<n; i++) {
_canvas.setPixel(r.x+Math.cos(angle)*r.rad, r.y+Math.sin(angle)*r.rad, 0xFFFFFF);
angle+=dA;
}
}
_canvas.applyFilter(_canvas, _canvas.rect, new Point(0,0), bf);
_canvas.applyFilter(_canvas, _canvas.rect, new Point(0,0), cmf);
}
}