# The Hitchhiker's Guide to the Mandelbrot Set

*This is a work-in-progress interactive explanation. I'd love feedback! You can reach
me at @blinry or sebastian@morr .cc.
*

Maybe you've seen an image of the Mandelbrot Set before. It's trippy, it's wonderous, it's beautiful. Here it is, have a look:

Click to zoom.

The Mandelbrot Set is a so-called *fractal*, which means it's self-similar.
Zooming in, you can always find smaller copies of itself. Maybe you encountered some
yourself when exploring the above image?

But what does this image mean? How is it constructed? It all begins with a sleeping bunny.

## Part 1: What is the Mandelbrot Set?

The Mandelbrot Set is the result of **repeated application of a very simple
rule**.

I'll attempt to explain to you how this works in a purely visual way, without any math. If, on the other hand, the math interests you, you can read up on this in the gray columns, but this is purely optional!

In our little world, there is a bunny, and a flag. You can place the flag everywhere you want. The bunny has its own free will. Psssst, it's still asleep! ... z z Z Z Z

The flag represents something which mathematicians call a *complex number*.
It's just like a normal number, but is has a funny little extra number attached to it,
which tells you how far it is above or below the number line. Mathematicians call it
the *imaginary component*, and mark it with an *i*. For example, in the
demo below, f = ?. Try placing the flag on -1.0+0.5i!

Drag the flag around. No surprises here.

The bunny always sleeps in the center of the lawn. But look, it woke up! It will now
start to walk and hop around. The first thing it always does is to
**walk** to the position of the flag. We call this movement *Step
1*.

The bunny's position is another complex number, which is initially *b _{0}
= 0*. The

**walk**movement is equivalent to adding

*f*, so the next position will be

*b*.

_{1}= fPull the slider to Step 1, then drag the flag around.

Step 2 consists of two movements: First, the bunny will **hop**! It has
a very particular way of hopping: It hops so that its angle to the right-direction
*doubles*, and the distance to its sleeping position *squares*.
Intuitively, if its distance to its sleeping position is less than 1, it will hop a
little bit closer, and if the distance is larger than 1, it will hop a little bit
farther away.

The **hop** movement is equivalent to squaring the current position.
The square of a complex number can be calculated using the binomial formula and the
fact that *i ^{2} = -1*:

*(x + yi)*. The behaviour described on the left can be explained using the polar form of complex numbers.

^{2}= x^{2}+ 2xyi + (yi)^{2}= x^{2}- y^{2}+ 2xyiPull the slider to Step 1.5, then drag the flag around.

The second movement of Step 2 is another **walk**. The bunny will walk
in the same direction and distance as it initially walked towards the flag:

After squaring *b _{1}*, we add

*f*again. This gives us

*b*.

_{2}= b_{1}^{2}+fAnd after that, the bunny just repeats these two movements: A hop, a walk, another hop, another walk. Let's look at how this looks for up to Step 4:

Let's get rid of the half-steps! From now on, we will treat the hopp-and-walk as a single movement.

Here's the same demo as before, but the the bunny directly goes full steps. The flag positions of this and the last demo are in sync, so you can compare the resulting path.

If we want to calculate the new position *b _{i+1}*, and we know the
old position

*b*, we can calculate

_{i}*b*. This is the only formula needed to calculate the Mandelbrot Set!

_{i+1}= b_{i}^{2}+fAnd NOW it gets exciting! What if we let our bunny do many, many, steps? Like, 100 of them? Look:

Pull the slider to Step 100, then drag the flag around.

Can you find another spiral? A star? A triangle?

Whaaaat. Crazy patterns everywhere!

You can see that for some flag positions, the bunny escapes the dashed circle (into FREEEEDOM!), while for others, it stays inside. Let's do an experiment: In the next demo, if the bunny's path leads it to freedom, we will color the current flag position white. If the bunny stays inside the circle, we will color it black (because it's so sad!)

This is the definition of the Mandelbrot Set: It consists of all flag positions for
which the bunny does not escape, if it does an *infinite number* of steps. Here,
we can only approximate: If the bunny hasn't escaped after 100 steps, it's probably
close to the Mandelbrot Set, and we will color the flag's position black.

Drag the flag around to scribble.

Why, helllll~o! You drew yourself a teeny tiny Mandelbrot set!

Let's add more color. So far, we only used white (for when the bunny escapes) and black
(for when it doesn't). In the next demo, let's count *how many* steps it took the
bunny to escape from the circle. If it took one step, we color the flag's position red. If
it took two, we color it orange, and so on. You can see the colors we use below the step
slider.

Drag the flag around to scribble.

And that's really all there is to it! Repeated application of a very simple rule, leading to incredibly complex detail.

Here's the last demo for now, which does all the drawing for you, and where you can zoom in. This one has a lot to explore.

Some things you can try:

- What happens to the path at the centers of the outer "bulbs"?
- Can you find out which period numbers are connected to each bulb? Do you see a relation to the "antennas" extending outward from that bulb?
- Zoom in on one of the bulbs. What happens to the path at the centers of its sub-bulbs?
- What is the period of the bulbs going "outward"? What happens if you follow a number of them?

Click to zoom. Middle-click to zoom out.

## Planned content

More fractals, for example:

The Tricorn: *b _{i+1} =
(b_{i}^{*})^{2}+f*

The Burning Ship: *b _{i+1} = (|Re(b_{i})| +
|Im(b_{i})|)^{2}+f*

What happens for other exponents than 2?

The Multibrot: *b _{i+1} =
b_{i}^{6}+f*

And what the hell are Julia Sets? Follow me on Twitter to get updated when the full thing comes out: @blinry

Thanks for reading!

## Comments?

Send a tweet to @blinry or drop
me a mail at sebastian@morr*.*cc. Also, you can support me on Patreon or subscribe to my newsletter !