Sixth TAD project. Draws Lorenz attractors. The algorithm I am using is from Clifford Pickover’s Computers and the Imagination: Visual Adventures Beyond the Edge. Click within the white square, below, to draw a new attractor:
Source code:
/**
* LorenzAttractor
* by Joshua Madara, hyperRitual.com
* Adapted from Clifford Pickover's
* _Computers and the Imagination_, p.125.
* Click in the display area to generate a new drawing.
*/
// define variables
float h = 0.01;
int npts = 4000;
float frac = 8 / 3;
float x = 0.6;
float y = 0.6;
float z = 0.6;
float xNew;
float yNew;
float zNew;
void setup() {
size(400, 400);
background(0);
stroke(255, 127);
smooth();
}
void draw() {
// draw border
line(0, 0, width-1, 0);
line(width-1, 0, width-1, height-1);
line(width-1, height-1, 0, height-1);
line(0, height-1, 0, 0);
}
void mousePressed() {
background(0);
translate(width/2, height/2);
// draw attractor
for(int i=0; i<npts; i++) {
xNew = x + h*10*(y-x);
yNew = y + h*((-x*z) + 28*x-y);
zNew = z + h*(x*y - frac*z);
line(x*(width/50), y*(height/50), xNew*(width/50), yNew*(height/50));
x = xNew; y = yNew; z = zNew;
// println("x:"+x+" y:"+y+" z:"+z);
}
translate(-(width/2), -(height/2));
}