// ---------------------------------------------------------------------- // Latoocarfian chaotic function // Implementation based on Clifford Pickover's book Chaos in Wonderland // Jim Plaxco, http://www.artsnova.com/processing/Latoocarfian-chaotic-function.html // ---------------------------------------------------------------------- // Global Variables float a,b,c,d; // the four parameters float Xold,Yold; // the old x,y values float Xnew,Ynew; // the new x,y values float scaleX=80; // scale to screen float scaleY=90; // scale to screen float mx,my; // x,y of screen center for translate void setup(){ size(800,600); // set the screen size background(255); // set the screen background to white stroke(0); // set the drawing color to black strokeWeight(2); // make larger points as a visibility aid mx=width/2; // get the x value for the middle of the screen my=height/2; // get the y value for the middle of the screen initializeVariables(); // call this function to initialize the variables } void draw(){ translate(mx,my); // relocate x,y origin to screen center Xnew = sin(Yold*b) + c*sin(Xold*b); // calculate the new x location Ynew = sin(Xold*a) + d*sin(Yold*a); // calculate the new y location point(Xnew*scaleX, Ynew*scaleY); // plot x,y after scaling them up Xold=Xnew; Yold=Ynew; // reset the old x,y values } void keyPressed(){ if(key==' ') { // make a new Latoocarfian drawing background(255); // erase the previous drawing initializeVariables(); // get a new set of values } else if(key=='p') { // print out the four parameters that were used in the form of a commented out statement println("// a="+a+ "; b=" + b+ "; c=" + c + "; d=" + d + "; //"); } } void initializeVariables() { // Restrict the values to the ranges suggested by Pickover in the book Chaos in Wonderland // Note that some combinations may result in little to be seen on-screen or in all points // being tightly clustered together. a = random(-3.0,3.0); b = random(-3.0,3.0); c = random(0.5,1.5); d = random(-0.5, 1.5); Xold= 0.1; Yold = 0.1; }