User login

Who's online

There are currently 0 users and 3 guests online.

Mandelbrot Set

Submitted by Adam King on 12 November, 2006 - 12:28.

The Mandelbrot Set

The Mandelbrot Set - showing interior details

The basic algorithm:

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:

Pseudo Code

  1. Let c be a complex constant
  2. Let z0 = 0 be the first complex iteration.
  3. Iterate once by letting zn = zn-12 + c.
  4. Repeat step 3 until one of the following occurs:
    • (a) The modulus (length) of zn exceeds a given value. This is our test for divergence.
    • (b) The number of iterations exceeds a given value. This is how we assume convergence.

The C code equivalent

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.

 

View the source code

MANDINT.C|MANDINT.H

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.