mdbtxt1
mdbtxt2
Proceed to Safety

# Color

Robert P. Munafo, 2023 Mar 21.

For the purpose of this discussion there are two types of color drawing situations.

"Limited color" refers to the situation where there is some rather small number N of colors available (typically 256 or less) and you specify which color to use by giving a single number from 1 to N.

"Full color" refers to the situation where you specify the color to use by giving three separate numbers, specifying the color in terms of some kind of three-dimensional color space (like red-green-blue, or hue-saturation-luminance)

## Limited Color

When working in limited color it is typical to pick a color from 1 to N based on the number of escape iterations of the point. If the number of iterations is less than N it can be used directly. If it is bigger than N you can pick a fixed "overflow" value, or use (iterations modulo N), which has the effect of cycling through the colors as many times as needed to cover all the possible iteration values.

## Full Color

The best approach when working in full color is to treat your available colors as a two-dimensional or three-dimensional space and plot each pixel with a color that combines different attributes of the iterated point, using dimensions in the color space. There are lots of possibilities; here are two examples:

Two dimensions of color, two attributes of point

use hue to show Escape Iterations

use brightness to show Distance Estimate

Three dimensions of color, three attributes of point

use hue to show Continuous Dwell

use saturation to show final point's Angle

use brightness to show final point's Radius

Both of these will produce fairly stunning results and of course there are dozens of other possible combinations.

One of the best ways to color the Mandelbrot Set uses the HSV color space. Use the Distance Estimator function for V. Use Escape-Iterations for H, with a somewhat different hue when the final point's Angle is between 0 and pi. Make S alternate between 1.0 and 0.67, to show odd and even values of Escape-Iterations. The result is stunning:

An HSV rendering

(as used in Color MANDELZOOM and its successors)

It is much better to use the hue/saturation/brightness system rather than something like red/green/blue, because of the psychology and physiology of human vision. Most good graphics environments provide a function that converts from HSV to RGB; if your's doesn't, look it up in a book like Graphics Gems or Fundamentals of Interactive Computer Graphics.

For each dimension you want to translate the attribute to the dimension in such a way that you use the whole range, and use it evenly. For example, hue is expressed as an angle on the color wheel. To convert iterations to hue, I would recommend some sort of logarithmic function, so if it takes 20 iterations to go around the wheel the first time, it takes another 40 to go around the second time, then 80, then 160 and so on. Then, to preserve the appearance of stripes at all iterations, you could add 20 degrees to the angle if the iteration is odd. The resulting formula would look like this:

hue = (360 * log2(iterations)) modulo 360 if (iterations mod 2 = 1) hue = (hue + 20) modulo 360

Hue based on iterations

## Algorithm Used in the Mu-Ency Illustrations

Most of the JPG and PNG images used to illustrate the Mu-Ency articles are colored using an algorithm similar to the following:

The intended benefits of this algorithm are:

• Always show all of the detail in an image, with lots of contrast
• Always show the dwell bands and binary decomposition
• Does not vary with zooming in and out or with changing the iterations (dwell) limit (in other words, an enlarged portion of any image always matches a recomputed version of just that portion)
• Use a color wheel that is rebalanced to match the human psychovisual color primaries (which gives what I consider aesthetically pleasing colors)
• Makes efficient use of the 3-D color space (for example by compensating for less information-carrying ability at low brightness values)
• Shows multiple hues, except when that would preclude any of the above

## More Examples

 Showing external angle only Showing filaments only Showing filaments and external angle Showing dwell and external angle Showing dwell and filaments continuous dwell

revisions: 20100907 oldest on record; 20101213 fix a couple typos; add "intended benefits"; 20221212 add illustrations; 20230321 add continuous dwell illustration

From the Mandelbrot Set Glossary and Encyclopedia, by Robert Munafo, (c) 1987-2024.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2023 Mar 22. s.27