24 bit coloring: Tutorial
By: Stephen C. Ferguson
Last modified: 9-28-98, 5:18 AM

This is a discussion on coloring fractal images with a 24 bit "true-color" technique. To color a pixel on most computers (PCs), components of red green and blue are used as values of 0 through 255. In coloring a fractal image a problem exist when a calculation goes beyond the value of 255. If a calculation is, say 300, then how does the pixel get colored? This is a problem that has been pondered by most all fractal programmers. One method that first comes to mind is to start back at 0 when the number exceeds 255. This is OK, but it leaves a sharp band from one color to the next when it goes from 255 to 0. Another method is to create a palette with 256 different colors and then interpolate between the colors of the palette. If a 1:2 interpolation is done, then 512 different colors can be achieved. This is a common method used among some programmers. Also custom palettes of up to 10000 colors can be created, but the color values have to initially be created from somewhere. It is assumed that a coloring palette contains colors that have smooth transitions from one color to the next. In other words, each of the neighbor colors is very close to the same color and this is referred to as a smooth color gradient.

This tutorial deals with a method for generating color values based on an algorithm that uses a sine and cosine calculation. The color component near the 255 range of the color is the maximum of the sine wave and colors close to 0 are at the minimum of the sine wave. Each red, green, and blue color component uses a separate sine or cosine wave to achieve a color blending.

 

 



Figure 1



const
const2PI: Double = 6.28318530718;
constNumSamples = 800;

// Generate some sample data
for i := 1 to constNumSamples do
begin
x[i] := i;
data := i;
data := const2PI * (data/360.0);

r[i] := sin(data);
g[i] := cos(data);
b[i] := -((r[i] + g[i])*0.707);

r[i] := (r[i]*127.0)+127.0;
g[i] := (g[i]*127.0)+127.0;
b[i] := (b[i]*127.0)+127.0;
end;


In Figure 1, some data is generated with values from 0 to 800. When the number 360 is reached, the RGB color will be the same as the color assigned to 0, it has gone a complete cycle. However the color gradient will be a smooth transition from one color to the next. This color technique is repeated up to the number 800, however it could be used for numbers all the way to infinity and the colors will be repeated with smooth transitions. The example shown here is only good for 360 colors.

This technique can be expanded. By varying the frequency of each color component, an almost unlimited number of color gradients can be created.

The data above is using 0 to 360 degrees to represent the calculations from fractal algorithms. After 360 degrees, the colors begin their cycle again. The color's amplitude at a particular cycle depends on the initial "starting" color. The color's frequency can be adjusted using a "step" value.

 

 

 

This page was created on 9/26/98

back to Iterations et Flarium24