spray
/**
* Copyright majoraze ( http://wonderfl.net/user/majoraze )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gT4j
*/
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.filters.BlurFilter;
public class Spray extends Sprite {
private var canvas:BitmapData;
private var color:uint;
private var size:Number = 50;
private var density:Number = 50;
public function Spray() {
init();
}
private function init():void {
canvas = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
var bmpCanvas:Bitmap = new Bitmap(canvas);
addChild(bmpCanvas);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseDown(e:MouseEvent):void {
color = Math.random() * 0xffffff + 0xff000000;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onMouseUp(e:MouseEvent):void {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
for (var i:int = 0; i < density; i++) {
var angle:Number = Math.random() * Math.PI * 2;
var radius:Number = Math.random() * size;
var xpos:Number = mouseX + Math.cos(angle) * radius;
var ypos:Number = mouseY + Math.sin(angle) * radius;
canvas.setPixel32(xpos,ypos,color);
}
}
}
}