# Color Mapping

#### Mapping an iteration count to a color in the Mandelbrot set

Method

When mapping the iteration count 1:1 to the color palette (linear mapping), the color distribution will be rather uneven because the
"density" of color bands increases with decreasing distance to the Mandelbrot set. In order to obtain a more even distribution of the
colors throughout the entire image, a non-linear function can be used to compress the colors at the lower end of the iteration count
and stretch them at the higher end. To achieve this, the iteration count (it) is first normalized to a value (x) from 0 to 1, then the
non-linear function is applied to x. The resulting value x which reaches from 0 to 1 as well is finally mapped to a color within the palette.

##### Example:

If the iteration count (it) in the image reaches from 50 to 200, then x is calculated as follows:

x = (it - minIt) / (maxIt - minIt)
= ([50...200] - 50) / (200 - 50)
= ([0...150]) / 150
= [0...1]

Next the non-linear function is applied:

Finally x is mapped to a palette of 256 colors:

color = x * 255
= [0...1] * 255
= [0...255]

Comparison Chart

The following comparison chart shows different methods for mapping an iteration count to a color in the Mandelbrot set.
Each image shows the same section of the Mandelbrot set, but with different linearities and – where applicable – different degrees
(parameter n) for the color gradient.
You can click on an image to open a JavaScript application in a new window / browser tab and draw the example image in full size (600 × 450 pixel).
There you can alter the parameters by yourself to see the effect "live".

Homepage > Mandelbrot Set in JavaScript > Mathematics > Color Mapping