Oct 28

ActionScript – Lorenz Attractor

Filed under: Playground | Taged as: , | Comments Off

The Lorenz Attractor, first introduced by Edward Lorenz in 1963, is a 3-dimensional structure corresponding to the long-term behavior of a chaotic flow. The result is a remarkable figure, a butterfly shape.

The equation itself reflects how the state of a dynamical system evolves over time in a complex, non-repeating pattern.

dx / dt = a (y - x)
dy / dt = x (b - z) - y
dz / dt = xy - c z

The ActionScript code draws the butterfly shape by repeatingly attaching a MovieClip to different positions and with a different scaling. The code shows the main section of the class.

private function init():Void{

var ref:LorenzAttractor = this;
_level0.onEnterFrame = function(){
if(ref.frames++ > ref.iterations) delete this.onEnterFrame;
ref.render();
}

}

private function render():Void{

frames++;

var x1:Number = x0 + h * a * (y0 - x0);
var y1:Number = y0 + h * (x0 * (b - z0) - y0);
var z1:Number = z0 + h * (x0 * y0 - c * z0);

draw(x0, y0, z0);

x0 = x1;
y0 = y1;
z0 = z1;
}

private function draw(x:Number, y:Number, z:Number):Void{

container.attachMovie("circle", "circle_" + frames, frames, {_x:y0*10, _y:x0*10, _xscale:z0*5, _yscale:z0*5});

}

Watch the lorenz attractor or download the ActionScript lorenz attractor

Comments are closed.