マウスを追従する光パーティクル | MouseEfectSample
package {
import flash.geom.*;
import flash.display.*;
import flash.filters.*;
import flash.events.*;
[SWF(width=440, height=440, frameRate=30, backgroundColor=0x000000)]
public class MouseEfectSample extends Sprite {
public function MouseEfectSample () {
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
}
public function mousemove(e:Event):void
{
for (var i:int = 0; i < 4; i++ ) {
var p:Particle = new Particle(
mouseX + (Math.random() * 10 -5) * 2,
mouseY + (Math.random() * 10 -5) * 2
);
addChild(p);
}
}
}
}
import flash.geom.*;
import flash.display.*;
import flash.filters.*;
import flash.events.*;
class Particle extends Sprite {
public function Particle (currentX:Number, currentY:Number) {
var size:int = Math.random() * 24;
var r:uint = Math.floor(Math.random() * 256);
var g:uint = Math.floor(Math.random() * 256);
var b:uint = Math.floor(Math.random() * 100 + 156);
var color:Number = (r << 16) | (g << 8) | (b);
var colors:Array = [color , 0x000000];
var fillType:String = GradientType.RADIAL;
var alphas:Array = [1, 1];
var ratios:Array = [0, 255];
var mtx:Matrix = new Matrix();
mtx.createGradientBox(size * 2, size * 2, 0, -size, -size); //createGradientBox(width:Number, height:Number, rotation:Number = 0, tx:Number = 0, ty:Number = 0):void
graphics.beginGradientFill(fillType, colors, alphas, ratios, mtx); //beginGradientFill(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0)
graphics.drawCircle(0, 0, size);
graphics.endFill();
x = currentX;
y = currentY;
blendMode = 'add';
addEventListener(Event.ENTER_FRAME, enterFrame);
}
private function enterFrame(e:Event):void {
alpha -= alpha * 0.1;
y += Math.random() * 4;
if (alpha <= 0.1) {
parent.removeChild(this);
removeEventListener(Event.ENTER_FRAME, enterFrame);
}
}
}