Mandelbrot & Julia Sets

Interactive visualization of fractals

By Juan Carlos Ponce Campuzano, 15/August/2018

The Mandelbrot Set

Essentially, the Mandelbrot set is generated by iterating a simple function on the points of the complex plane. The points that produce a cycle (the same value over and over again) fall in the set, whereas the points that diverge (give ever-growing values) lie outside it. When plotted on a computer screen in many colors (different colors for different rates of divergence), the points outside the set can produce pictures of great beauty. The boundary of the Mandelbrot set is a fractal curve of infinite complexity, any portion of which can be blown up to reveal ever more outstanding detail, including miniature replicas of the whole set itself.

The Mandelbrot set is certainly the most popular fractal, and perhaps the most popular object of contemporary mathematics of all. Since Benoît B. Mandelbrot (1924-2010) discovered it in 1979-1980, while he was investigating the mapping $z \rightarrow z ^2+c$, it has been duplicated by tens of thousands of people around the world (including myself).

Constructing the Mandelbrot Set

Here is how the Mandelbrot set is constructed. Take a starting point $z_0$ in the complex plane. Then we use the quadratic recurrence equation $$z_{n+1}=z_{n}^2+z_0$$ to obtain a sequence of complex numbers $z_n$ with $n=0, 1, 2, \ldots$. The points $z_n$ are said to form the orbit of $z_0$, and the Mandelbrot set, denoted by $M$, is defined as follows:

If the orbit $z_n$ fails to go to infinity, we say that $z_0$ is contained within the set $M$. If the orbit $z_n$ does go to infinity, we say that the point $z_0$ is outside $M$.

Take, for example, $z_0=1$. Then we have \[ \begin{array}{rcl} %\hline %\text{ } & z_{n+1}=z_{n}^2+z_0 \\ %\hline z_0 &=& 1 \\ %\hline z_1 &=& 1^2 + 1 = 2 \\ %\hline z_2 &=& 2^2 + 1 = 5\\ %\hline z_3 &=& 5^2 + 1 = 26 \\ %\hline z_4 &=& 26^2 + 1 = 677 \\ %\hline &\vdots& \end{array} \] As you can see, $z_n$ just keeps getting bigger and bigger. Thus $z_0=1$ is not in the Mandelbrot set. But if we choose different values for $z_0$ this won't always be the case. Consider now the value $z_0=i$. In this case, we obtain: \[ \begin{array}{rcl} %\hline % \text{ } &=& z_{n+1}=z_{n}^2+z_0 \\ %\hline z_0 &=& i \\ %\hline z_1 &=& i^2 + i = -1 + i \\ %\hline z_2 &=& (-1+i)^2 + i = -2i+i = -i\\ %\hline z_3 &=& (-i)^2 + i = -1+i \\ %\hline z_4 &=& (-1+i)^2 + i = -i \\ %\hline &\vdots& \end{array} \] It is clear that in this case further iterations will just repeat the values $−1+i$ and $−i$. All of these complex numbers lie within distance 3 of the origin. So they stay in a bounded subset of the plane; they do not run out to infinity. So the number $z_0=i$ is in the Mandelbrot set.

Colorful Mandelbrot Set

The simplest algorithm for generating a representation of the Mandelbrot set is known as the escape time algorithm. A repeating calculation is performed for each $x$, $y$ point in the plot area and based on the behavior of that calculation, a color is chosen for that pixel.

In the following applet, the HSV color scheme is used and depends on the distance from point $z_0$ (in exterior or interior) to nearest point on the boundary of the Mandelbrot set. In other words, provided that the maximal number of iterations is sufficiently high, we can obtain a picture of the Mandelbrot set with the following properties:

  1. Every pixel that contains a point of the Mandelbrot set is colored black.
  2. Every pixel that does not cotain a point of the Mandelbrot set is colored using hue values depending on how close that point is to the Mandelbrot set.

Now explore the Mandelbrot set. Zoom in or out in different regions. Change the number of iterations and observe what happens to the plot. You can also plot the orbit.

+: Zoom In   -: Zoom Out   R=Reset view    O=Orbit    I=Information & Frame

The Julia Set

In the previous section we showed how the Mandelbrot set can be generated using the expression \[z_{n+1}=z_{n}^2+z_0.\] This is a particular case of the quadratic recurrence equation \begin{eqnarray}\label{julia} z_{n+1}=z_{n}^2+c \end{eqnarray} with $c$ a fixed complex number. The set we obtain with this equation is known as the Julia set. In fact, there is a different Julia set for almost every $c$.

Similarly as we did for the Mandelbrot set, we obtain a sequence of complex numbers $z_n$ with $n=0,1,2,\ldots$. Again, the points $z_n$ are said to form the orbit of $z_0$, and the Julia set is defined as follows:

If the orbit $z_n$ fails to escape to infinity, the initial $z_0$ is said to belong to the filled-in Julia Set.

The Julia set is named after the French mathematician Gaston Julia who investigated their properties in 1915 and culminated in his famous paper in 1918: Mémoire sur l’itération des fonctions rationnelles. While the Julia set is now associated with the quadratic polynomial in (\ref{julia}), Julia was interested in the iterative properties of a more general expression, namely \[z^4 + \frac{z^3}{z-1} + \frac{z^2}{z^3 + 4 z^2 + 5} + c.\] The Julia sets, defined by the equation (\ref{julia}), can take all kinds of shapes, and a small change in $c$ can change the Julia set very greatly. In 1979, with the help of computer, B. B. Mandelbrot studied the Julia sets and tried to classify all the possible shapes and came up with a new shape: the Mandelbrot Set.

Explore the Julia sets in the applet below. Zoom in or out in different regions. Change the number of iterations and observe what happens to the plot. Move the mouse around and observe the different Julia sets depending of the value of $c$.

+: Zoom In   -: Zoom Out   R=Reset view    O=Orbit    I=Information & Frame

The Mandelbrot and Julia Sets Connection

Due to the definition of the Mandelbrot set, there is a close correspondence between the geometry of the Mandelbrot set at a given point and the structure of the corresponding Julia set. In other words, the Mandelbrot set forms a kind of index into the Julia set. A Julia set is either connected or disconnected, values of $c$ chosen from within the Mandelbrot set are connected while those from the outside of the Mandelbrot set are disconnected. The disconnected sets are often called dust, they consist of individual points no matter what resolution they are viewed at.

Explore the relationship between the Mandelbrot and Julia sets in the following applet. Move the mouse over to the Mandelbrot set to observe different Julia sets. Zoom in or out in different regions. Open the Controls menu to change the number of iterations or choose an specific value of $c$.

+: Zoom In   -: Zoom Out   R=Reset view    O=Orbit    I=Information & Frame

This applet was recently included in some of the animations for the following video from Quanta Magazine:

Further reading

All the applets were made with p5.js and the source code can be found here:

If you want to learn how to program them yourself, I recommend you these tutorials:

I also recommend you some of the most widely read basic introductions to the Mandelbrot and Julia sets:

They all cover other fascinating fractals and contain many spectacular pictures.

Finally, if you are adept at programming, then you can easily translate the pseudocode below into C++, Python, JavaScript, or any other language. For each pixel on the screen perform this operation:

  x0 = x co-ordinate of pixel
  y0 = y co-ordinate of pixel

  x = 0
  y = 0

  iteration = 0
  max_iteration = 1000

  while ( x*x + y*y <= (2*2) AND iteration < max_iteration )
    xtemp = x*x - y*y + x0
    y = 2*x*y + y0

    x = xtemp

    iteration = iteration + 1

  if ( iteration == max_iteration )
    color = black
    color = iteration

If you find this content useful, please consider supporting my work using the links below.

∞ Thanks!