# Mandelbrot Colorings

> One equation, seven color formulas: change a slider to recolor the Mandelbrot set with cosine, polynomial, band and parity colorings. Edit each formula.

The picture of the Mandelbrot set comes from one number per pixel: how quickly the iteration $z \to z^2 + c$ escapes. The colors are a separate choice, and this document shows seven formulas for the same equation. Change $m$ to compare them. Each one is a formula that you can edit.

In the color formula, $z$ is the value of the row, the smooth escape count divided by 256. It equals 1 inside the set. In this view, 90% of the pixels outside the set have a value below $0.033$, so a linear color map shows them in a small part of its range. The helper $L(v) = \ln(1 + 256v)/\ln 257$ spreads those values over $[0, 1]$ on a log scale. The formulas write $\max(v, 0)$ for $v$ so that the GPU can draw them: it does not take a logarithm of a value that could be negative.

$m = 1$, *cosine palette*: each channel is $0.5 + 0.5\cos(2\pi(\log_2(1 + 256z)/2 + d))$, with a different phase $d$. The colors repeat each time the count is multiplied by 4.

$m = 2$, *Bernstein polynomials*: the channels are $9(1-L)L^3$, $15(1-L)^2L^2$ and $8.5(1-L)^3L$, which give dark blue far from the set and orange near it.

$m = 3$, *glow*: one hue in OKLCH, with the lightness $0.12 + 0.88L^2$, so that the filaments are bright on a dark background.

$m = 4$, *bands*: the lightness has a period of one escape count, which draws the curves where the value is constant.

$m = 5$, *triangle wave*: a wave with a power curve moves between dark red and amber.

$m = 6$, *parity*: a point is black or white according to whether the integer part of the count is even or odd, and the interior is red.

$m = 7$, *anatomy*: the interior is colored with the exact tests for two parts of the set. With $q = (x - 1/4)^2 + y^2$, a point is in the main cardioid when $q(q + x - 1/4) \le y^2/4$, and in the period-2 bulb when $(x + 1)^2 + y^2 \le 1/16$. The small bulbs stay dark because these tests do not include them.

These formulas use only the escape value. Other methods, such as distance estimation and stripe averages, use the whole orbit of each point, so they need more than this one number.

*The cosine palette is from Inigo Quilez, the polynomial channels are from Solarian Programmer, and the triangle wave and the parity bands are from Junpei Sekino's page on coloring fractals.*

- [Open the interactive version](https://graph-paper.io/showcase/en/mandelbrot-colorings)
- [Learn more on Wikipedia](https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set)
