﻿ Mandelbrot Set

### Mandelbrot Set

The Mandelbrot set is a mathematical set of points whose boundary is a distinctive and easily recognizable two-dimensional fractal shape. The set is closely related to Julia sets (which include similarly complex shapes) and is named after the mathematician Benoit Mandelbrot, who studied and popularized it.

The basic function, in C++ using OpenGL, to generate this set is:

void renderMandelbrot(void)
{
int x, y, cnt, maxIter;
complex z, t, t2;
maxIter = 256.0;
imaginaryXMandelbrot = (maxXMandelbrot - minXMandelbrot) / (GLdouble)currScreenWidth;
imaginaryYMandelbrot = (maxYMandelbrot - minYMaldenbrot) / (GLdouble)currScreenHeight;
for (x = 0, z.x = minXMandelbrot; x < currScreenWidth; x++, z.x += imaginaryXMandelbrot)
{      // z = x + i*y;
for (y = 0, z.y = minYMaldenbrot; y < currScreenHeight; y++, z.y += imaginaryYMandelbrot)
{
t2 = z;
cnt = 0;
while ((t2.x * t2.x + t2.y * t2.y <= 4) && (cnt < maxIter))
{
t.x = t2.x*t2.x - t2.y*t2.y + z.x;
t2.y = 2 * t2.x*t2.y + z.y;
t2.x = t.x;
cnt++;
// x = x^2 - y^2 + x0; -> 1 + 3
// y = 2 * x * y + y0; -> 2 + 4
}
}
}
}

And heeere is the result:   In my program you are able to move coordinate axis with arrow keys, also to zoom in and out with keys Q and A. Also to speed up or slow down zooming with the keys W and S, change colours simply by pressing C.