Skip to main content

What is the Mandelbrot Set?

The Mandelbrot set is one of the most famous fractals in mathematics, named after Benoît Mandelbrot who studied it in 1980. It’s defined as the set of complex numbers c for which the iterative function does not diverge to infinity.
The Mandelbrot set is defined by the recursive formula: z(n+1) = z(n)² + c, where both z and c are complex numbers, and z starts at 0.

Mathematical Definition

For each point c in the complex plane:
  • Start with z = 0
  • Repeatedly apply the formula: z = z² + c
  • If the magnitude of z remains bounded (doesn’t escape to infinity), then c is in the Mandelbrot set

The Escape-Time Algorithm

The renderer uses an escape-time algorithm to determine whether a point belongs to the set. Here’s the actual implementation from the source code:
void handle_pixel(int x, int y, t_fractol *fractol)
{
    t_complex z;
    t_complex c;
    int i;
    int color;

    i = 0;
    // Map screen coordinates to complex plane
    z.x = (map(x, -2, +2, WIDTH) * fractol->zoom) + fractol->shift_x;
    z.y = (map(y, +2, -2, HEIGHT) * fractol->zoom) + fractol->shift_y;
    
    // For Mandelbrot: c = z (starting point)
    c.x = z.x;
    c.y = z.y;
    
    // Iterate until escape or max iterations
    while (i < fractol->iterations_definition)
    {
        z = sum_complex(sqare_complex(z), c);  // z = z² + c
        
        // Check if escaped (magnitude² > escape_value)
        if ((z.x * z.x) + (z.y * z.y) > fractol->escape_value)
        {
            // Color based on iteration count
            color = map(i, PSYCHEDELIC_LIME, PSYCHEDELIC_MINT,
                    fractol->iterations_definition);
            return;
        }
        i++;
    }
    // Point didn't escape - it's in the set (colored white)
}

Complex Number Operations

The fractal computation relies on complex number arithmetic:

Squaring a Complex Number

t_complex sqare_complex(t_complex z)
{
    t_complex result;
    
    result.x = (z.x * z.x) - (z.y * z.y);  // Real part
    result.y = 2 * z.x * z.y;               // Imaginary part
    return (result);
}

Adding Complex Numbers

t_complex sum_complex(t_complex z1, t_complex z2)
{
    t_complex result;
    
    result.x = z1.x + z2.x;  // Add real parts
    result.y = z1.y + z2.y;  // Add imaginary parts
    return (result);
}

Key Parameters

Escape Value

Default: 4The threshold for determining if a point has escaped. When |z|² > escape_value, the iteration stops.Higher values may reveal more detail but increase computation time.

Iteration Count

Default: 30 iterationsMaximum number of times to apply the formula before considering a point as part of the set.More iterations reveal finer detail at the set’s boundary but render more slowly.
The escape value of 4 is mathematically proven: if |z| > 2, then the sequence will diverge. Since |z|² = z.x² + z.y², we check against 4 (which is 2²).

Visual Characteristics

When you run the Mandelbrot fractal, you’ll see:
The largest black region (actually rendered as white in this implementation) represents points that never escape - the actual Mandelbrot set. This is the characteristic “cardioid” shape with a circular bulb attached.
The colorful psychedelic patterns around the set represent how quickly points escape. The color gradient transitions from PSYCHEDELIC_LIME (0x00FF00) to PSYCHEDELIC_MINT (0x98FF98) based on iteration count.
As you zoom in (using the mouse wheel), you’ll discover infinite self-similar patterns along the boundary. The fractal never runs out of detail - you can zoom forever and always find new structures.
The renderer maps the complex plane from approximately -2 to +2 on both axes, centered on the origin. This range captures the entire main structure of the Mandelbrot set.

Running the Mandelbrot Set

To launch the Mandelbrot fractal explorer:
./fractol Mandelbrot
The window opens at 2000x1500 pixels with the complete Mandelbrot set visible. Use the controls to navigate and explore:
  • Mouse wheel to zoom in/out
  • Arrow keys or WASD to pan
  • +/- to adjust iteration detail

Mathematical Insights

Why does this create such complex patterns?The boundary between points that escape and those that don’t is infinitely complex. The simple formula z² + c produces chaotic behavior at the boundary, creating the intricate, self-similar structures you see when zooming in.

Interesting Regions to Explore

  • Seahorse Valley: Located along the main body’s west side
  • Elephant Valley: Found at coordinates around (-0.75, 0.1)
  • Spiral Regions: Near the connection points between bulbs
  • Minibrots: Tiny copies of the entire set appear throughout the fractal
Adjust the iterations_definition parameter (using +/- keys) when zoomed in deeply. More iterations are needed to properly render fine details at high zoom levels.

Build docs developers (and LLMs) love