Mathematical explanation and step-by-step implementation guide
The Mandelbrot set is a mathematical set of complex numbers that produces beautiful fractal patterns when visualised. It was discovered by Benoit Mandelbrot in 1980 and has become one of the most famous examples of mathematical beauty.
The set is defined by a surprisingly simple iterative formula applied to complex numbers, yet it produces infinitely complex patterns. What makes it special is that you can zoom into the boundary forever and keep finding new intricate structures at every scale.
Complex numbers have the form a + bi, where:
To multiply complex numbers: (a + bi)(c + di) = (ac - bd) + (ad + bc)i
For each complex number c, we test whether it belongs to the Mandelbrot set by repeatedly applying this formula:
Starting with z₀ = 0, we calculate:
In practice, we use two rules to decide if a number is in the set:
Let's test whether c = 0.3 + 0.5i is in the Mandelbrot set:
For this value, |z| remains less than 2 throughout many iterations, so c = 0.3 + 0.5i is in the Mandelbrot set.
The beautiful colours you see in Mandelbrot images aren't part of the mathematical set itself — the Mandelbrot set is typically shown as dark! The colours represent how quickly points outside the set escape to infinity:
The main Mandelscope explorer uses "Smooth Periodic Wave Colouring" which creates fluid rainbow patterns by using the final iteration count and the magnitude of z to generate smooth, continuous colour transitions.
Complex numbers are essential because they give us a 2D space to explore. The real part of c corresponds to the x-axis (horizontal position), and the imaginary part corresponds to the y-axis (vertical position). This allows us to visualise the set as an image where each pixel represents testing a different complex number.
Julia sets are closely related to the Mandelbrot set: instead of fixing z₀ = 0 and varying c, we fix c to a specific value and vary z₀. Each point in the Mandelbrot set corresponds to a different Julia set. Points inside the Mandelbrot set produce connected Julia sets, while points outside produce disconnected "dust" Julia sets.
You can explore Julia sets in the main Mandelscope application by clicking on any point in the Mandelbrot view!
Here's a complete, minimal implementation in JavaScript using a 2D canvas. This code draws a simple two-colour Mandelbrot set with no additional features.
600×450 pixels, 100 iterations per point
Editable Code: Try modifying the code below and click "Run Code" to see your changes!
maxIterations to 50 or 200 to see how detail changes'#ff5555', '#88ff88', or experiment with different hex codesif (iterations < 10) ctx.fillStyle = '#999';