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

Lorenz Attractor

Lorenz attractor
Get Adobe Flash player
by ton 26 Dec 2008
    Embed
//Lorenz attractor
package {
    import flash.events.Event;
    import flash.display.*;
    [SWF(frameRate=60, backgroundColor=0)]
    public class Lorenz extends Sprite {
        private const P:Number = 10;
        private const R:Number = 28;
        private const B:Number = 8 / 3;
        private const D:Number = 0.01;
        private const SCALE:int = 6;
        private const M:Number =  Math.cos(75*Math.PI/180)
        private var _x:Number = 0.1;
        private var _y:Number = 0;
        private var _z:Number = 0;
        private var dx:Number;
        private var dy:Number;
        private var dz:Number;
        private var canvas:Shape = new Shape;

        public function Lorenz() {
            canvas.x = stage.stageWidth/2;
            canvas.y = stage.stageHeight*4/5;
            canvas.graphics.lineStyle(0, 0xffffff);
            addChild(canvas);
            addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
        }

        private function onEnterFrameHandler(event:Event):void {
            dx = P * (_y - _x);
            dy = _x * (R - _z) - _y;
            dz = _x * _y - B * _z;
            _x += D * dx;
            _y += D * dy;
            _z += D * dz;
            canvas.graphics.lineTo(_x * SCALE, -(_y * M + _z) * SCALE);
        }
}
}