forked from: ぱーてぃくる花火 [corrected leak]
corrected leak - now safe and endless 花火
@Hasufel
// forked from Susisu's ぱーてぃくる花火
// corrected leak - now safe and endless 花火
// @Hasufel
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.StageQuality;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.events.Event;
import net.hires.debug.Stats;
[SWF(width="465", height="465", backgroundColor="0x0", frameRate="60")]
public class Rain extends Sprite{
private var h:int = stage.stageHeight;
private var w:int = stage.stageWidth;
private var bmpData:BitmapData=new BitmapData(h,w,true,0);
private var filterObj:BlurFilter;
private var obj:Array=[];
private var angle:int;
private var pt:int=50;
private var cols:Array=[Math.round(Math.random()*255),Math.round(Math.random()*255),Math.round(Math.random()*255)];
public function Rain(){
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.quality=StageQuality.LOW;
addChild(new Stats());
filterObj=new BlurFilter(2,2,2);
addChild(new Bitmap(bmpData)) as Bitmap;
addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event):void{
for (var j:int=0;j<3;j++){
cols[j]+=Math.floor(Math.random()*9)-4;
if(cols[j]>255){cols[j]=255;}else if(cols[j]<0){cols[j]=0;}
}
for(var i:int=0;i<pt;i++){
angle=Math.round(Math.random()*360);
createParticle(Math.cos(angle/180*Math.PI)*Math.random()*5,Math.sin(angle/180*Math.PI)*Math.random()*5,0xff000000|cols[0]<<16|cols[1]<<8|cols[2],mouseX,mouseY);
}
var o:int = obj.length;
bmpData.applyFilter(bmpData,bmpData.rect,new Point(0,0),filterObj);
bmpData.lock();
while(o--) {
var p:Particle = obj[o];
p.x+=p.vx;
p.y+=p.vy;
p.vx*=.95;
p.vy*=.95;
bmpData.setPixel32(p.x,p.y,p.c);
if (p.vx+p.vy<.1&&p.vx+p.vy>-.1){obj.splice(o,1);}
}
bmpData.unlock();
}
private function createParticle(vx:Number, vy:Number, c:uint, xx:Number=0, yy:Number=0):void {
var p:Particle = new Particle();
p.x = xx;
p.y = yy;
p.vx = vx;
p.vy = vy;
p.c = c;
obj.push(p);
}
}
}
class Particle {
public var x:Number;
public var y:Number;
public var vx:Number;
public var vy:Number;
public var c:uint;
}