Clifford Attractor
/**
* Copyright ser1zw ( http://wonderfl.net/user/ser1zw )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/biOG
*/
package {
import flash.display.Sprite;
[SWF(width="400", height="300", backgroundColor="#ffffff")]
public class CliffordAttractor extends Sprite {
private var a:Number;
private var b:Number;
private var c:Number;
private var d:Number;
private var scale:Number;
private const WIDTH:int = 400;
private const HEIGHT:int = 300;
private const CENTER_X:int = WIDTH / 2;
private const CENTER_Y:int = HEIGHT / 2;
private const DOT_SIZE:Number = 0.3;
public function CliffordAttractor() {
a = -1.4;
b = 1.6;
c = 1.0;
d = 0.7;
scale = Math.max(WIDTH, HEIGHT) / 4;
Draw(30000);
}
private function Draw(n:uint):void {
var i:uint;
var x:Number = 0;
var y:Number = 0;
var xNext:Number;
var yNext:Number;
for (i = 0; i < n; i++) {
xNext = Math.sin(a * y) + c * Math.cos(a * x);
yNext = Math.sin(b * x) + d * Math.cos(b * y);
x = xNext;
y = yNext;
this.graphics.beginFill(0x0000ff);
this.graphics.drawCircle(CENTER_X + x * scale, CENTER_Y - y * scale, DOT_SIZE);
this.graphics.endFill();
}
}
}
}