Moving magic spots
// forked from 1623's forked from: forked from: magic spots
// forked from nabe's forked from: magic spots
// forked from mrdoob's magic spots
package
{
import flash.display.*;
import flash.geom.*;
import flash.events.Event;
import net.hires.debug.Stats;
import caurina.transitions.Tweener;
[SWF (backgroundColor="0x00000099")]
public class Magic extends Sprite
{
private var item : Sprite;
private var items : Vector.<Sprite> = new Vector.<Sprite>;
public function Magic()
{
stage.frameRate=40;
opaqueBackground=0;
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init( e : Event ) : void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.quality = "low";
var i : int;
for (i = 0; i < 500; i++)
{
items[i] = item = new Sprite();
var xpos : int = Math.random() * stage.stageWidth;
var ypos : int = Math.random() * stage.stageHeight;
var size : int = Math.random() * 100;
function tween(item:Sprite,delay:Number=0):void
{
Tweener.addTween(item,
{
x:Math.random()*stage.stageWidth,
y:Math.random()*stage.stageHeight,
time:2+2*Math.random(),
transition:"easeInOutQuad",
delay:delay,
onComplete:tween,
onCompleteParams:[item]
});
}
tween(item,Math.random()*3);
var fillType:String = GradientType.RADIAL;
var colors:Array = [0xffffff, 0xffff00 , 0xff0000,0x0000ff];
var alphas:Array = [1,.2, 0.1,0];
var ratios:Array = [0x00,0xa0,0xd0, 0xFF];
var mtr:Matrix = new Matrix();
mtr.createGradientBox(size * 2, size * 2, 0, -size, -size);
var spreadMethod:String = SpreadMethod.PAD;
item.graphics.beginGradientFill(fillType, colors, alphas, ratios, mtr, spreadMethod);
item.graphics.drawCircle(0, 0, size);
item.graphics.endFill();
item.x = xpos;
item.y = ypos;
item.scaleX = item.scaleY = 0;
item.blendMode = "add";
addChild(item);
}
//addChild( new Stats );
addEventListener(Event.ENTER_FRAME, loop);
}
private function loop( e : Event ) : void
{
for (var i : int = 0; i < items.length; i++)
{
item = items[i];
var distance : int = Math.sqrt( Math.pow(mouseX - item.x, 2) + Math.pow(mouseY - item.y, 2));
var scale : Number = 1 - (distance * 0.01);
scale = (scale > 1) ? 1 : (scale < 0) ? 0 : scale;
item.scaleX = item.scaleY += ( scale - item.scaleY ) * .15;
item.alpha = item.scaleX*40;
item.visible = item.scaleX > 0;
}
}
}
}