How does a program decide which colour to draw for a point of the Mandelbrot set?
It counts iterations until the orbit escapes the radius-2 disk, then maps that count to a colour.
For each pixel the program converts screen coordinates to a complex number c and starts the orbit at z = 0. It applies z(n+1) = z(n)^2 + c repeatedly. The moment |z| exceeds 2, the point cannot be in the Mandelbrot set and the loop stops. The number of completed iterations is the escape count.
The escape count is then fed to a palette. A common scheme is a linear or cyclic gradient where count 0 is one hue, count 50 another, and counts beyond the cap are drawn in a single interior colour. Because the count grows without bound near the boundary, the palette is usually cyclic so that colour bands appear as contour-like rings.
If the orbit never escapes within the chosen cap — say 100, 500 or 1000 iterations — the point is declared inside the set and painted with the interior colour. The cap is a rendering choice, not a property of the set: raising it reveals more structure near the boundary but costs time roughly in proportion to the cap.
- Start with z = 0 and the pixel's c.
- Iterate z ← z² + c.
- Stop when |z| > 2 or the iteration cap is reached.
- Map the iteration count to a colour; cap reached means interior colour.
What does the iteration count actually measure?
It measures how long the orbit stays bounded before it provably diverges.
The Mandelbrot set is the set of c for which the orbit of 0 stays bounded forever. In practice a program cannot test 'forever', so it uses the escape radius as a sufficient condition for divergence: once |z| > 2 the orbit is guaranteed to run to infinity.
The escape count is therefore a lower bound on the true escape time. Points with low counts are far outside the set; points with counts near the cap sit close to the boundary. This is why the boundary is where the colour bands crowd together.
Interior colouring by distance estimation needs the derivative of the iteration along with z, which gives a smooth estimate of the distance to the boundary instead of a flat interior fill.
- Low count: point is well outside the set.
- High count near the cap: point is near the boundary.
- Cap reached: point is treated as inside for this render.