forked from: magic spots
import net.hires.debug.Stats;
package{
import flash.display.*;
import flash.events.Event;
import flash.geom.*;
// import net.hires.debug.Stats;
[SWF(backgroundColor="0x000000")]
public class MagicSpots extends Sprite{
private var item : Sprite;
private var items : Array = [];
private var balls:Array = [];
private const NUM:int =20;
public function MagicSpots(){
for(var i:int=0;i<NUM;i++){
balls.push(new ball(stage));
}
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init( e : Event ) : void{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.quality = "low";
for (var i : int = 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;
var fillType:String = GradientType.RADIAL;
var colors:Array = [ Math.random() * 0xffffff , 0x000000];
var alphas:Array = [100, 100];
var ratios:Array = [0x00, 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++){
var maxScale:Number=0;
item = items[i];
// var distance : int = Math.sqrt( Math.pow(mouseX - item.x, 2) + Math.pow(mouseY - item.y, 2));
for(var j:int = 0;j<balls.length;j++){
var distance : int = Math.sqrt( Math.pow(balls[j].pos.x - item.x, 2) + Math.pow(balls[j].pos.y - item.y, 2));
var scale : Number = 1 - (distance * 0.01);
scale = (scale> 1) ? 1 : (scale < 0) ? 0 : scale;
if(maxScale<scale)maxScale=scale;
}
item.scaleX = item.scaleY += ( maxScale - item.scaleY ) * .3;
item.visible = item.scaleX> 0;
}
for(var k:int = 0;k<balls.length;k++){
balls[k].Update(stage);
}
}
}
}
import flash.geom.Point;
import flash.display.Stage;
class ball{
public var pos:Point;
public var vec:Point;
private const spd:Number = 15;
public function ball(stage:Stage){
pos = new Point(Math.random() * stage.stageWidth,Math.random() * stage.stageHeight);
var rad:Number = Math.random()*Math.PI*2;
vec = new Point(Math.cos(rad)*spd,Math.sin(rad)*spd);
}
public function Update(stage:Stage):void{
pos.x += vec.x;
pos.y += vec.y;
if(pos.x<0||stage.stageWidth<pos.x){
vec.x*=-1;
}
if(pos.y<0||stage.stageHeight<pos.y){
vec.y*=-1;
}
}
};