Layman's explanation of the Mandelbrot graphs

The formal definition of the Mandelbrot set demands far more from the reader than is really needed to actually play around with this stuff. Here's an attempt at a simpler explanation.

The basics

A complex number is no more than two distinct values paired together like this (a, b), complete with a full set of rules how to perform arithmetics on them. We can view these numbers as coordinates in an image, with the first value denoting the horizontal coordinate x, and the second number denoting the vertical coordinate y. Then each point in the image has its distinct complex value (x,y).

The actual coordinates in a image will have their own set of values between, say, (0,0) and (999,999) for a square image. However, we can define these complex values as covering a completely different set of values.

Let's say the lower left corner of the image represents the complex value (-2,-2) and the upper right corner is (2,2). The image point (340,523) then represents the complex number (-0.64,0.092). Now we have our own coordinate system to work with.

The algorithm

To produce the mandelbrot image, we have to go through every point in the image, find the complex number of each point and go through asimple procedure to determine whether it's inside or outside the Mandelbrot Set, and then paint that point white or black (or maybe some other color).

For each point, let's call its corresponding complex number "c". We need another complex number "z", which we initially set to the same value as c (I use the equality sign to denote assignment here - these are not equations):

z = c

Now, we calculate a new value of z:

z = z2 + c

The new value of z may be within the limits of the image, or it may point outside its limits. Once the value has passed outside a circle around (0,0) with a radius of 2, there is no way for the value to get back inside this circle. Then we say that z is "escaping".

So we do this over and over again until the value has passed outside this circle, and we also count the number of times we do the calculation - the number of iterations. Once z is outside the circle, or we have done the calculation a certain maximum number of times, we stop.

Now comes the crucial part: at this point, if z is still within the circle with a radius of 2, we say that the original point c is "inside the Mandelbrot set" and we paint it black. if z has escaped, c is outside the Mandelbrot set, and we paint it white.

And that's it - if we do this for each point in the image, we will get the image on the right.

Adding color

To make the colorful images that you can see on this page and elsewhere, we do the same thing, but instead of painting the points outside the Mandelbrot set white, we choose a color based on how many iterations it took for z to escape, and we're there.

The simplicity of complex arithmetics

Now for the complex arithmetic. The only calculation we do is

z = z2 + c

which is the same as

z = z * z + c

To add two complex numbers, we just add their respective components, so

(a1,b1)+(a2,b2) = (a1+a2,b1+b2)

To multiply a complex number (a1,b1) by another (a2,b2) to make a new number (a,b), just do

a = a1 * a2 - b1 * b2

b = a1 * b2 + a2 * b1

In this case we are multiplying z by z, so if we write z as (x,y) and c as (x0,y0) we get

x = x2 - y2 + x0

y = 2 * x * y + y0

This is the only complex arithmetic you really need to know about for this.