In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Gravity Lines

Get Adobe Flash player
by ton 31 Dec 2008
    Embed
package {
    import flash.display.*;
    import flash.events.Event;
    [SWF(width=465, height=465, frameRate=60, backgroundColor=0x000000)]
    public class GravityLines extends Sprite {
        private const SIZE:int = 465;
        private const G:Number = 10000;
        private const N:int = 3;
        private var list:Array = new Array();
        private var canvas:Shape = new Shape();
        private var bmd:BitmapData;
        
        public function GravityLines():void {
            bmd = new BitmapData(SIZE, SIZE, true, 0x000000);
            addChild(new Bitmap(bmd));
            for (var i:int = 0; i < N; i++) {
                var p:Particle = new Particle();
                p.x = Math.random() * SIZE;
                p.y = Math.random() * SIZE;
                p.vx = Math.random() * 6 - 3;
                p.vy = Math.random() * 6 - 3;
                list.push(p);
            }
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        
        private function enterFrameHandler(e:Event):void {
            var g:Graphics = canvas.graphics;
            g.clear();
            g.lineStyle(0, 0xffffff, 0.2);
            for (var i:int = 0; i < N; i++) {
                var p:Particle = list[i];
                g.moveTo(p.x, p.y);
                p.x += p.vx;
                p.y += p.vy;
                g.lineTo(p.x, p.y);
                if (p.x < 0) {
                    p.x = SIZE;
                }else if (p.x > SIZE) {
                    p.x = 0;
                }
                if (p.y < 0) {
                    p.y = SIZE;
                }else if (p.y > SIZE) {
                    p.y = 0;
                }
            }
            g.lineStyle(0, 0xffffff, 0.05);
            for (i = 0; i < N - 1; i++) {
                var p1:Particle = list[i];
                for (var j:int = i + 1; j < N; j++) {
                    var p2:Particle = list[j];
                    var dx:Number = p2.x - p1.x;
                    var dy:Number = p2.y - p1.y;
                    var dis:Number = Math.sqrt(dx * dx + dy * dy)
                    var ax:Number = dx / G;
                    var ay:Number = dy / G;
                    p1.vx += ax;
                    p1.vy += ay;
                    p2.vx -= ax;
                    p2.vy -= ay;
                    g.moveTo(p1.x, p1.y);
                    g.lineTo(p2.x, p2.y);
                }
            }
            bmd.draw(canvas);
        }
    }

}
class Particle {
    public var x:Number;
    public var y:Number;
    public var vx:Number;
    public var vy:Number;
}