forked from: HANABI
色々参考にさせて頂いてます
/**
* Copyright zsp ( http://wonderfl.net/user/zsp )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4K4L
*/
// forked from yamatk's forked from: HANABI
// forked from yanbaka's HANABI
// 色々参考にさせて頂いてます
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.PixelSnapping;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Timer;
[SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "30")]
public class Hanabi extends Sprite
{
private const WIDTH:Number = 465;
private const HEIGH:Number = 465;
private var _particles:Array;
private var _canvas:BitmapData;
private var _glow:BitmapData;
private var _rect:Rectangle;
private var cTra:ColorTransform;
private var timer:Timer;
private var sx:Number;
private var sy:Number;
private var t0:int =0;
private var t1:int = 30;
private var bl_step:int = 100;
private var t_interval:int = 500;
private var phase:int = 1;
public function Hanabi()
{
init();
}
private function init():void
{
_particles = [];
_canvas = new BitmapData(WIDTH, HEIGH, false, 0x0);
addChild(new Bitmap(_canvas)) as Bitmap;
/*
_glow = new BitmapData(WIDTH/4, HEIGH/4, false, 0x0);
var bm:Bitmap = addChild(new Bitmap(_glow, PixelSnapping.NEVER, true)) as Bitmap;
bm.scaleX = bm.scaleY = 4;
bm.blendMode = BlendMode.ADD;
*/
_rect = new Rectangle(0, 0, WIDTH, HEIGH);
cTra = new ColorTransform(.8, .8, .9, 1.0);
this.stage.addEventListener(Event.ENTER_FRAME, enterframeHandler);
timer = new Timer(6);
timer.addEventListener(TimerEvent.TIMER, resetFunc);
timer.start();
}
private function resetFunc(e:TimerEvent):void
{
hanabi();
}
//弾生成 一周終わったらfalse返す。
private function bulletgenerate01():Boolean{
if (bl_step>0){
//var angle:Number = t0+bl_step*100;//((t0%bl_step)*Math.PI*2 )/bl_step;
var angle:Number = ((t0%bl_step)*Math.PI*2 )/bl_step;
createParticle(angle);
createParticle((angle+Math.PI)%(Math.PI*2));
}
if (t0%bl_step==0) bl_step--;
if(bl_step <=0) {
/* t_interval--;
if (t_interval <=0) {
t_interval = 500;
bl_step =100;
}*/
return false;
}
return true;
}
private function hanabi():void
{
sx = 233;
sy = 233;
t0++;
switch (phase){
case 0: if(!bulletgenerate01()) {
phase++;
t0 =0
}
break;
case 1:
var angle:Number = (t0+t0/t1);// +t1*t1/20 -t1*t1*t1/40);
createParticle(angle);
if(t0%20==0) t1--;
if (t0==2500) {
phase =0;
t1 = 300
t0 = 0;
}
break;
default:break;
}
}
private function createParticle(angle:Number):void{
var p:Particle = new Particle();
p.x = 233;
p.y = 233;
p.vx = Math.cos(angle) *2;
p.vy = Math.sin(angle) *2;
_particles.push(p);
}
private function enterframeHandler(e:Event):void
{
update();
}
private function update():void {
_canvas.lock();
//_canvas.applyFilter(_canvas, _rect, new Point(), new BlurFilter(1, 1));
_canvas.colorTransform(_rect, cTra);
var i:int = _particles.length;
while (i--) {
var p:Particle = _particles[i];
//p.vy += 0.02;
p.vx *= 0.995;
p.vy *= 0.995;
p.x += p.vx;
p.y += p.vy;
_canvas.setPixel32(p.x, p.y, p.c);
if ((p.x > stage.stageWidth || p.x < 0) || (p.y < 0 || p.y > stage.stageHeight) || Math.abs(p.vx) < .01 || Math.abs(p.vy) < .01)
{
this._particles.splice(i, 1);
}
}
_canvas.unlock();
_glow.draw(_canvas, new Matrix(0.25, 0, 0, 0.25));
}
}
}
class Particle
{
public var x:Number;
public var y:Number;
public var vx:Number;
public var vy:Number;
public var c:uint;
public function Particle()
{
this.x = 0;
this.y = 0;
this.vx = 0;
this.vy = 0;
this.c = 0xFFFFFFFF;
}
}