Mandelbrot set

By Omar Essilfie-Quaye

Github Repo Link to github repository Docs Link to source code documentation

Complex Maths

The Mandelbrot set is a 2D set which lies in the complex plane. It has been featured in a lot of popular culture a prominent example being in the novel "The Ghost from the Grand Banks" written by Arthur C Clarke. There are a few attractions to this particular set, I personally find the self repeating nature to be attractive, in this particular case the Mandelbrot set is a fractal.

The mathematical description of the Mandelbrot set is fairly simple. The set is defined in the complex plane as the complex numbers \(c\) for which the function \(f_{c}(z) = z^{2} + c\) does not diverge to infinity when iterated starting at \(z=0\). This is difficult to visualise even for those familiar with complex functions, therefore the pseudo code for generating the plot above is shown below.

Pseudocode Example

          
let xx = linspace(xLowerLimit, xUpperLimit, xNumPts);
let yy = linspace(yLowerLimit, yUpperLimit, yNumPts);

let img = createImage(xNumPts, yNumPts);

for(let i = 0; i < xx.length; i++) {
    for(let j = 0; j < yy.length; j++) {
        x = xx[i];
        y = yy[j];

        let c = math.complex(x, y);
        let itt = 1;
        let z = c;

        while(itt < maxSteps && z.mul(z.conjugate()).re < threshold) {
            z = z * z + c;
            itt ++;
        }
        img.set(i, j, color(255 - itt * itt, 255 - itt, 255 - itt));
    }
}