The Mandelbrot Set

The entire Mandelbrot set fractal is contained in the simple formula:
Z = Z2 + C
Where C is the (x,y) point being tested, expressed as a complex number x + iy. The formula is iterated starting with Z = 0, and each time setting the new Z value to Z2 + C. The Mandelbrot set is defined as all points C for which Z remains finite when iterated forever. It will "orbit" around the origin, spinning around but never moving farther away than a distance of 2.
The Mandelbrot set is connected, which means that there are no detached pieces. You can walk from any point in the set to any other point in the set without ever stepping outside it. The Mandelbrot set is also vertically symmetric. If you flip the fractal upside-down, it's the same!
The complex number arithmetic is equivalent to the following real arithmetic:
Let C = x + iy where x and y are real
Let Z = a + ib where a and b are real
Then Z2 = (a2 − b2) + i(2ab)
and Z2 + C = (a2 − b2 + x) + i(2ab + y)
Geometrically, complex squaring is a rotation. If you express the point Z in polar coordinates with radius r and angle θ, the operation Z2 doubles the angle and squares the radius.
Click on the graph to place the point Z, and it will calculate Z2 animated along a circular path. (The points are labeled in polar complex notation Z = reiθ).
This is what creates the fractal's swirly nature. Every iteration rotates the point by its own angle, squares the distance, and then moves it by C, which makes the next rotation be around a different center point.
For example, to test if the point (−1, 0.3) is in the set:
Let C = −1 + 0.3i
Z = 0
Z2 + C = −1 + 0.3i
(Z2 + C)2 + C = −0.09 − 0.3i
((Z2 + C)2 + C)2 + C = −1.0819 + 0.354i
(((Z2 + C)2 + C)2 + C)2 + C = 0.04519161 − 0.4659852i
...
Mathematically, this is written as an infinite sequence:
Zn+1 = Zn2 + C
Click on the graph to place the point C. It will calculate the iterations and draw the oribit of Z. If you click inside the Mandelbrot set, it will bounce around and sometimes make a periodic pattern, but it will stay inside. If you click outside the set, no matter how close, the point will eventually fly out to infinity (diverge).
Because it's impossible to iterate forever, the computer stops after a maximum number of iterations, or stops early if Z gets too big. If the magnitude of Z becomes greater than 2, then it will only grow with more iterations, so we can be sure that C is not in the set.
This image was generated using 28 iterations. The blue colors represents areas where Z grew too big before all 28 iterations had completed. These areas are strictly outside the set, but Z grows more slowly when you are near the set, so the number of iterations it takes to "escape" produces a nice glow effect. The white areas have finished all 28 iterations, and are probably inside the set, but doing more iterations will reveal some white areas that aren't in the set.
It takes more iterations (more computational effort) to draw a clearer image as you get closer to the boundary of the Mandelbrot set. The detail of the fractal also increases. Each Mandelbrot set iteration increases the number of complex number rotations and thus the "swirlyness" of the fractal.
For example, look at the fractal boundary when using 28 iterations:
(Click to Open in the Mandelbrot Viewer)
Now watch as the number of iterations is increased from 28 to 128:
Now zoom into the area on the left, and increase to 2048 iterations. Look at these "octopus" patterns! They're much more complex than anything you can find using only 28 iterations.
(Click to Open in the Mandelbrot Viewer)
As you can see, the patterns become more and more artistic, swirly, and beautiful as you increase the number of iterations! Mathematically, with an infinite number of iterations, it becomes a fractal. The Hausdorff dimension of the Mandelbrot set boundary is 2, which means that although the boundary is seemingly a 1-dimensional curve, it is so infinitely complex that it fills space as effectively as a 2-dimensional object.
My favorite place in the fractal is these snowflakes, at 128 iterations:
(Click to Open in the Mandelbrot Viewer)
If you zoom in far enough, everything will become pixelated, but that is not the end of the fractal! The pixel blocks are merely the end of your computer's number precision. It takes more digits to go deeper into the fractal, which becomes too slow to compute in real time. The Mandelbrot fractal is like the digits of pi. It goes on forever, but gets harder to compute the further you go.