Home

My attempt at the

Mandelbrot Set

This is my personal attempt at recreating what is probably the most famous fractal ever: the Mandelbrot Set.

The beauty of this fractal lies in its infinite complexity emerging from a deceptively simple mathematical rule. No matter how far you zoom in, you'll always find new intricate patterns.

The simple idea behind it

The Mandelbrot set is based on a surprisingly simple formula involving complex numbers:

zn+1 = zn² + c

Here's what happens:

  1. Start with z = 0
  2. Pick a point c on the complex plane (each pixel represents a different c)
  3. Apply the formula repeatedly: square the current value and add c
  4. If the value stays bounded (doesn't shoot off to infinity), that point is in the set (colored black)
  5. If it escapes to infinity, color it based on how quickly it escaped

The colorful regions show points that escape, with colors indicating the speed of escape. The black region is the actual Mandelbrot set!

Implementation challenges

The main challenge was mapping pixels to complex numbers. Each pixel (x, y) on the screen needs to correspond to a complex number c = a + bi on the complex plane.

I had to scale the pixel coordinates to fit the interesting region of the Mandelbrot set (roughly -2 to 1 on the real axis, -1.5 to 1.5 on the imaginary axis).

Another challenge was determining the escape condition: how many iterations before we decide a point has escaped? Too few iterations and you miss detail; too many and the rendering slows down significantly.