Exploring the Mandelbrot Set and Julia Sets
The set of all 'C' where iterating fC(Z) -> Z2+C, starting at Z=0, does not diverge to ∞.
11th August 2021
Julia sets are either connected (one piece) or a dust of infinitely many points. The Mandelbrot set is those 'c' for which the Julia set is connected.
I have always been fascinated by geometry and fractals since first seeing the Mandelbrot set back in the Triassic period, well, the 1980s. Since then I have written various scripts to try to reveal the fractal geometry hidden around us in nature.
These geometries are incredibly simple to define, a little harder to code. The Mandelbrot set, for example, comes from repeating a single equation, z = z2 + c, over and over for every point on the screen. Points that stay bounded belong to the set, and points that escape towards infinity are coloured according to how quickly they flee. That one line of maths produces endless spirals, seahorse tails and miniature copies of the whole shape, no matter how far you zoom in.
The fractal below is drawn on a canvas element using WebGL. Because every pixel can be calculated independently, the work is handed to your graphics card, which crunches thousands of points in parallel. If you turn on hardware acceleration in Chrome --> Settings --> System, you should get super smooth results.
A short history
The word "fractal" was coined by the mathematician Benoit Mandelbrot in 1975, from the Latin fractus, meaning broken. The first computer images of the set that now carries his name appeared around 1980, and they caused a sensation. Here was something of astonishing complexity, generated by an equation a schoolchild could write down.
The groundwork had been laid decades earlier. Around 1918, the French mathematicians Gaston Julia and Pierre Fatou studied what happens when you repeat simple equations like this one. They worked entirely with pen and paper, so they could reason about these shapes but never actually see them. It took the arrival of the computer to reveal what they had been describing.
How the Mandelbrot and Julia sets are related
Both sets use exactly the same equation, but they ask different questions. For the Mandelbrot set, z always starts at zero and every point on the screen tries a different value of c. For a Julia set, c is fixed, and every point on the screen is a different starting value of z.
That means every point on the Mandelbrot set has its own Julia set, and the Mandelbrot set acts as a map of all of them. Pick a point inside the black area and its Julia set is one connected shape. Pick a point outside and the Julia set shatters into a scattering of disconnected dust. The most beautiful Julia sets come from points right on the edge, where the Mandelbrot set is at its most intricate. That is exactly what the demo below lets you explore.
Fractals in the wild
Nature was using these patterns long before anyone wrote them down. A few of my favourite examples:
- Romanesco broccoli, where each spiral cone is built from smaller spiral cones.
- Ferns, whose fronds are made of smaller fronds that mirror the whole leaf.
- Coastlines, which seem to get longer the more closely you measure them. Mandelbrot himself wrote a famous paper on this in 1967, asking how long the coast of Britain really is.
- Lightning and river deltas, branching again and again in similar ways at every scale.
- Blood vessels and lungs, which use repeated branching to pack an enormous surface area into a small space.
It is humbling to think that these mathematical entities are all around us and barely hidden from view. Once you start recognising fractal forms, you will see them everywhere in nature, from the frost on a winter window to the clouds drifting overhead.
Questions you might be asking
Is the Mandelbrot set infinite?
Yes and no. The whole set fits comfortably inside a circle of radius 2, and its area is only about 1.5 square units. Its boundary, however, is infinitely long and infinitely detailed, so you could zoom in forever and never run out of new shapes.
Where do the colours come from?
The set itself is just black. The colours show how many repetitions each point outside the set took to escape, which reveals the bands and swirls surrounding it.
Why does the image eventually go blocky when I zoom in?
Graphics cards are fast because they use fairly short numbers. Zoom in far enough and the gap between neighbouring pixels becomes smaller than those numbers can represent. Very deep zooms need special high precision arithmetic, which is far slower.
If this has caught your imagination, take a look at the Sierpinski gasket in 3D and the Menger Sponge, two more fractals built from surprisingly simple rules.
Here is a Mandelbrot set:
Click anywhere on the Mandelbrot below to see the corresponding Julia Set; each position should give different results.
script monkey: business solutions using digital intelligence