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

forked from: BrownianMotion

Get Adobe Flash player
by ton 19 Jan 2009
// forked from ton's BrownianMotion
package {
    import flash.display.*;
    import flash.geom.Rectangle;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class BrownianMotion extends Sprite {

        private const N:int = 500;
        private const F:Number = 0.95;
        private const MAX_R:int = 50;
        private const X:Number = 0.2;
        private const W:int = 465;
        private const H:int = 465;

        private var list:Vector.<Dot>;
        private var canvas:Sprite = new Sprite();
        private var bmd:BitmapData;
        function BrownianMotion() {
            bmd = new BitmapData(stage.stageWidth, stage.stageHeight);
            addChild(new Bitmap(bmd));
            list = new Vector.<Dot>(N, true);
            for (var i:int = 0; i < N; i++) {
                var mc:Dot = new Dot(Math.random()*0xffffff);
                var r:Number = Math.sqrt(Math.random()) * MAX_R;
                var angle:Number = Math.random() * (2 * Math.PI);
                mc.x = W/2 + Math.cos(angle) * r;
                mc.y = H/2 + Math.sin(angle) * r
                mc.vx = 0;
                mc.vy = 0;
                canvas.addChild(mc);
                list[i] = mc;
            }
            addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
            
        }

        private function onEnterFrameHandler(event:Event):void {
            for (var i:int = 0; i < N; i++) {
                var mc:Dot = list[i];
                mc.vx += Math.random() * X * 2 - X;
                mc.vy += Math.random() * X * 2 - X;
                mc.vx *= F;
                mc.vy *= F;
                mc.x += mc.vx;
                mc.y += mc.vy;
            }
            bmd.draw(canvas);
        }
    }
}


import flash.display.Sprite;
class Dot extends Sprite{
    public var vx:Number;
    public var vy:Number;
    public var color:uint;
    function Dot(color:uint) {
        this.color = color;
        this.graphics.beginFill(color);
        this.graphics.drawCircle(0, 0, 1);
        this.graphics.endFill();
    }
}