/* There is a lot going on in this example of Fractals. Two types of fractals are used here, both based on one base class Fractal. The Mandelbrot fractal set is an image that should be somewhat familiar, and this example takes a look at how recursion fits into fractal drawing. The second fractal type, the Julia set, takes a look at how fractal images can change based upon the values used to control them. */ // We'll use one of each type of fractal Mandelbrot mandel; Julia julia; // Max Iterations controls the recursion for the Mandelbrot fractal // we're using int maxIter; // Switch between Mandelbrot and Julia fractals int mode = 0; void setup() { // Set the environment size(400, 400); background(0); framerate(15); // Set the mandelbrot fractal mandel = new Mandelbrot(); maxIter = 1; // Setup the julia set fractal julia = new Julia(); } void draw() { // Choose which of the fractals we're drawing if (mode == 0) { drawMandel(); } else { drawJulia(); } } void drawMandel() { // Set how deep recursion should go mandel.setMaxIterations(maxIter); // draw the fractal mandel.render(); // increment and contain the iterations maxIter++; if (maxIter > 40) { maxIter = 1; } } void drawJulia() { // figure out where in the Real/Imaginary space our mouse is pointing double real = julia.getRealAtX(mouseX); double imag = julia.getImaginaryAtY(mouseY); // Set these real and imaginary numbers as the controlling values of the fractal julia.setCore(real, imag); // render the julia set julia.render(); } void mousePressed() { // Switch which fractal we're drawing. mode++; mode = mode % 2; }