forked from: flash on 2010-4-22
/**
* Copyright taishun ( http://wonderfl.net/user/taishun )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qpzM
*/
// forked from kiyobu's flash on 2010-4-22
package {
import flash.display.Sprite;
import flash.geom.Point;
import flash.events.Event;
public class FlashTest extends Sprite {
public const AG2RG:Number = Math.PI / 180;
public var list:Array = new Array(50);
public function FlashTest() {
var lgh:uint = list.length;
for(var i:uint = 0; i < lgh; i++){
list[i] = new Point2(random(stage.stageWidth), random(stage.stageHeight));
list[i].ag = random(360);
list[i].spX = Math.cos(list[i].ag * AG2RG) * 2;
list[i].spY = Math.sin(list[i].ag * AG2RG) * 2;
}
addEventListener(Event.ENTER_FRAME, loop);
}
public function loop(e:Event):void{
graphics.clear();
graphics.moveTo(list[0].x, list[0].y);
var lgh:uint = list.length;
for(var i:uint = 0; i < lgh; i++){
var scl:Number = (i/lgh);
list[i].x += list[i].spX * scl;
list[i].y += list[i].spY * scl;
if (list[i].x > stage.stageWidth){
list[i].x = stage.stageWidth;
list[i].spX *= -1;
} else if (list[i].x < 0){
list[i].x = 0;
list[i].spX *= -1;
}
if (list[i].y > stage.stageHeight){
list[i].y = stage.stageHeight;
list[i].spY *= -1;
} else if (list[i].y < 0){
list[i].y = 0;
list[i].spY *= -1;
}
graphics.beginFill(0x666666, 1);
graphics.drawCircle(list[i].x, list[i].y, 5 * scl);
graphics.endFill();
if (i > 0){
graphics.lineStyle(scl, 0x666666, scl);
graphics.lineTo(list[i -1].x, list[i -1].y);
}
}
}
public function random(n:Number):Number{
return Math.floor(Math.random()*n);
}
}
}
import flash.geom.Point;
dynamic class Point2 extends Point {
public function Point2(xx:Number, yy:Number){
x = xx;
y = yy;
}
}