Revision History

Version 1.02
I added Japanese language support and expanded the range of shades from 32 to 256. I also added an option to fill in the bounded regions with the chosen color, rather than black.

Version 1.01
Added Russian language support.

Version 1.0
Original version.


Contact info

  • Email: rglovejoy at gmail dot com
  • Skype: rglovejoy

Official PayPal Seal

How does it work?

Some of you may be curious about how these wonderful shapes are created.

First Principles

Let's begin with the very basic principles of complex numbers.

The numbers that you are familiar with (1, -2.7, e, π, etc.), are called real numbers. You may recall the number line you used in grammar school. Each of the numbers listed has a place on the number line.

One of the properties of positive numbers is that you can find their square roots. A square root of a number is a number that when multiplied by itself gives you the original number. For example, the square root of 9 is 3. 3 × 3 gives us 9. Or in other words:

This works well with the square roots of positive numbers (we don't care about zero right now). What happens if we want to find the square root of a negative number, such as -1? This is a problem, because the square root of a negative number does not exist. There is no such thing, because when you square a number, you always get a positive value:

1 × 1 = 1
-1 × -1 = 1
-1 × 1 = -1

Mathematicians recognized this problem a very long time ago and invented a placeholder, which they called an imaginary number, or i (electrical engineers sometimes call it j, to avoid confusion with the symbol for current, which can be i or I). So, we can have:

A combination of a real number and an imaginary number is called a complex number. An example of a complex number would be 2 + 2i. The value 2 is the real part of the number and 2i is the imaginary part. Multiplying two complex numbers is just like multiplying two algabraic expressions:

We can also represent a complex number as a vector on a plane, where the x-axis represents real values and the y-axis represents imaginary values. So, the expression 2 + 2i would look like this:

The next part of this essay will focus on the Mandelbrot set itself, however, if you would like to learn more about how complex numbers work, you may take a look at the Complex number article on Wikipedia. Another good starting point is Wolfram Research's Mathworld site.

The Mandelbrot Set

Now that we have the preliminaries out of the way, we can discuss the Mandelbrot set with more detail. At its heart, the set can be expressed with the equation

Here, Z and c are complex values. The way it works is that we start with the initial condition that Z0 = 0 and c is an arbitrary value on the complex plane (like the one shown above). What we then do is iterate, that is, we start at the n = 0 state and then we find what Z is in the n = 1 state. Then we take Z1 and find what Z2 is, and so on.

As we iterate, we need to set a limit on how far we want to go. Mandelbrot discovered that Z can do one of two things: it can remain stable, not changing very much over the course of the iteration, or its value can explode. The test I use is to see if the square of the length of Z is greater than 4.

As an aside, I should emphasize that this is not something that can be predicted analytically, it needs to be found numerically, through the process of iteration. If you were going to try to solve the problem analytically, you would find yourself dealing with large polynomial values very quickly:

As you can see, by the time n=4, we have already built up an eighth-order polynomial. Since we want to find out at what value n does Z explode, this is not a practical route to follow.

At any rate, let's see what happens when we set c to be 1 + i:

Clearly, when n = 2, |Zn|2 blows right past 4. Suppose now, we say that c = 0 + 0i. What happens is that Z never changes, it always stays at 0.

What Mandelbrot did was to put together a map of all the places where c was found. If the value of Z remains stable, we color it black. If it explodes, we color that spot with a value, maybe based on the number of iterations it took for Z to blow up. What he ended up with is something like this:

And that's all there is to it. I will be adding more commentary to this essay, but these are the essentials of how the Mandelbrot set works. If you would like to learn more, Wikipedia is a very good source.