みじん斬り
SwordsEffect Scratch
* by ish-xxxx
/**
* SwordsEffect Scratch
* by ish-xxxx
*/
package {
import flash.display.*;
import flash.filters.*;
import flash.events.*;
import flash.geom.*;
import caurina.transitions.*;
[SWF(frameRate=45, backgroundColor=0x020202)]
public class Swords extends Sprite {
//CONSTANTS/////////////////////////////
private const MAIN_BG_COLOR:uint=0x2;
private const MAIN_BG_ALPHA:Number=1.0;
private const SWORD_ALPHA:Number=0.5;
private const SWORD_EDGE:uint=5;
private const ATTACK_SPEED:uint=5;
private const ATTACK_INTERVAL:uint=2;
private const ATTACK_TRANSITION:Function=Equations.easeInOutExpo;
private const ATTACK_END_TRANSITION:Function=Equations.easeOutExpo;
//VARS//////////////////////////////////
private var count:uint=0;
public function Swords():void {
init();
}
private function init():void {
setup();
}
private function setup():void {
stage.addEventListener(Event.ENTER_FRAME,update,false,0,false);
}
private function update(ev:Event):void {
if (count % ATTACK_INTERVAL == 0) {
var sp:Sprite=new Sprite ;
var gra:Graphics=sp.graphics;
var color:uint=getColor();
gra.beginFill(color,SWORD_ALPHA);
gra.drawRoundRect(0,0,1,SWORD_EDGE,SWORD_EDGE);
gra.endFill();
sp.x=Math.random() * stage.stageWidth | 0;
sp.y=Math.random() * stage.stageHeight | 0;
var ranX:uint=Math.random() * stage.stageWidth | 0;
var ranY:uint=Math.random() * stage.stageHeight | 0;
var cp:Point=new Point(sp.x,sp.y);
var tp:Point=new Point(ranX,ranY);
var dist:Number=Point.distance(cp,tp);
var ranScale:uint=dist;
var rad:Number=getRadian(tp,cp);
sp.rotation=Radian2Degree(rad);
sp.alpha=0;
sp.filters = [getBlur()];
addChild(sp);
Tweener.addTween(sp,{alpha:1,scaleX:ranScale,time:ATTACK_SPEED / 10,transition:ATTACK_TRANSITION});
Tweener.addTween(sp,{x:tp.x,y:tp.y,scaleX:0,alpha:0,delay:ATTACK_SPEED / 10,time:ATTACK_SPEED / 5,transition:ATTACK_END_TRANSITION,onComplete:kill,onCompleteParams:[sp]});
}
count++;
}
private function getColor():uint {
var ranR:String=String(uint(Math.random() * 255 | 0));
var ranG:String=String(uint(Math.random() * 255 | 0));
var ranB:String=String(uint(Math.random() * 255 | 0));
var res:uint=uint(ranR + ranG + ranB);
return res;
}
private function getBlur() : BlurFilter{
var b:BlurFilter = new BlurFilter();
b.blurX = Math.random() * 10 | 0;
b.blurY = Math.random() * 10 | 0;
b.quality = BitmapFilterQuality.LOW;
return b
}
private function kill(target:Sprite):void {
removeChild(target);
target=null;
}
private function getRadian(tp:Point,cp:Point):Number {
var dx:Number=tp.x - cp.x;
var dy:Number=tp.y - cp.y;
return Math.atan2(dy,dx);
}
private function Radian2Degree(radian:Number):Number {
return radian * 180 / Math.PI;
}
}
}