# Latoocarfian Chaotic Function Tutorial Illustration: Image slice from A Day In The Life Of A Latoocarfian

By Jim Plaxco

Difficulty Level: Beginner

The heart of algorithmic art is the use of mathematics to create compositions of points, lines, and shapes that are aesthetically pleasing. The field of algorithmic art took on a new look with the introduction of fractal and chaotic functions.

One of these chaotic functions is the Latoocarfian chaotic function. This function was one of the mathematical subjects covered in the book Chaos in Wonderland: Visual Adventures in a Fractal World by Clifford Pickover. The illustration A Day In The Life Of A Latoocarfian was created using a version of the Latoocarfian chaotic function.

The Latoocarfian function relies on the use of the sine function and four parameters. Two of the parameters are used to modify the sine of the x and y input coordinates and the other two are used as sine scaling factors.

The process of identifying four parameters that produce an aesthetically pleasing work of mathematical art is quite an adventure given the infinite number of combinations of values.

If you would like to explore this chaotic function for yourself, following is a pseudocode implementation of the algorithm that can be easily translated into the programming language of your choice.

### Pseudocode Implementation of the Latoocarfian chaotic function

````Set A to a random number so that -3 < A < 3`
`Set B to a random number so that -3 < B < 3`
`Set C to a random number so that 0.5 < C < 1.5`
`Set D to a random number so that 0.5 < D < 1.5`
`Set Xold to an initial non-zero value so that -0.5 < Xold < 0.5`
`Set Yold to an initial non-zero value so that -0.5 < Yold < 0.5`
`  `
`Do Forever or Until Boredom Sets In`
`  Set X = sin(Yold * B) + C * sin(Xold * B)`
`  Set Y = sin(Xold * A) + D * sin(Yold * A)`
`  Put a Dot on the Screen at X, Y`
`  Set Xold = X`
`  Set Yold = Y`
`  Go Back to the Do Statement`
`End of Do Loop`
```

One word of caution. The range of X and Y values that this equation is going to produce is going to be small. By range I mean that all the Xs and Ys are going to be not very far from zero. If you want to be able to see the pattern the equation creates, you will need to multiply your X and Y by some number so as to scale the output to the size of your screen. For example, instead of putting a dot at X,Y you will want to put the dot at X*100, Y*100. And be aware that scaling factors that work well for one combination of parameter values may cause the next combination to be drawn outside your screen's boundaries.

Following is the source code for an implementation of the Latoocarfian chaotic function in the Processing programming language. If you prefer, you can download the source code as a Processing PDE

### Processing Language Version of the Latoocarfian chaotic function

````// --------------------------------------------------------------`
`// Latoocarfian chaotic function `
`// Implementation based on Clifford Pickover's Chaos in Wonderland`
`// By Jim Plaxco`
`// http://www.artsnova.com/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 screen center for translate`
`  `
`void setup(){`
`  size(800,600)); // set the screen size`
`  background(255);// set screen background to white`
`  stroke(0);      // set drawing color to black`
`  strokeWeight(2);// make larger points for visibility`
`  mx=width/2;     // set x value for screen middle`
`  my=height/2;    // set y value for screen middle`
`  initializeVariables(); // call function to initialize variables`
`}  `
`  `
`void draw(){`
`  translate(mx,my);               // relocate 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`
`  // 1) little to be seen on-screen or `
`  // 2) 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;`
`} `
```

### Latoocarfian Function Variations

The four parameters a,b,c,d are the key to the output that the program creates. You can experiment by coming up with your own set of ranges for the values. Or maybe you want to define a specific relationship between paramters. For example:

````A = random(-3.0,3.0); // get a random value for A`
`B = sqrt(abs(A)):     // make B the square root of the absolute value of A`
```

Experimenting with the bounds and relationships between the parameters can produce surprising results. Additionally you may want to try using a different trigonometric function or combination of functions instead of the sine function to see what happens.

One very important note: if you find that you've created a Latoocarfian that you really like, make sure that you record the values of the parameters a,b,c,d as the odds are greatly against you ever coming across that particular combination of parameter values again.

### Concluding Thoughts

Algorithmic art, such as that illustrated here with the Latoocarfian chaotic function, is a stimulating and challenging combination of mathematics, algorithm design, and programming. The two most important things are 1) don't be afraid to experiment, and 2) mistakes aren't because they can result in new insights and discoveries.