It's a way of life

The central loop of a Mandelbrot program repeats (iterates) the following simple equation:
z -> z2 + c
Here, both z and c are complex numbers, each of which have a real and an imaginary part of the form (a + bi).
If we state that z = (x + y i) and c = (cr + ci i), we can split the above equation into real and imaginary parts, and manipulate it using simple algebraic operations we get:
x = (x * x) - (y * y) + cr;
y = 2 * x * y + ci;
Using this formula, the central program loop could look like this:
while(xsq + ysq < 4.0 && it < maxIter)
{
xsq = x * x;
ysq = y * y;
y = 2 * x * y + ci;
x = xsq - ysq + cr;
it++;
}To get the Mandelbrot Set image, the x and y axies represent the values applied to the constant value c. The image above shows the full Set with the following initial values:
X Axis Minimum: -2
X Axis Maximum: 0.8
Y Axis Minimum: -1.3
Y Axis Maximum: 1.3
Maximum Iterations: Over 100
|z| (Modulus of z): < 4.0
A simple program could colour the resulting point (x, y) according to the number of iterations it took to break out of the loop.
This code would produce a Mandelbrot Set with a solid interior colour (often black), however, the program supplied in the fractal pack adds some additional logic to the code to colour the interior showing extra information about the values of z within the set itself.
Post new comment