2.3. Specifying Colors

Colors in Gamma are represented by 24 bit hexadecimal numbers ranging from 0x000000 to 0xffffff. The first 8 bits correspond to the red value, the next 8 to the green value, and the last 8 to the blue value. For example, 0x00ff00 would be pure green.

Most people find it easier to think in decimal notation, though, and the red, green, and blue colors are often assigned values from 0 - 255, representing a scale of intensity from black to full color. Gamma allows for such red/green/blue notation for colors with the PgRGB function. It converts colors expressed in red/blue/green decimal notation to a single hexadecimal number. For example:

Gamma> lightblue = PgRGB(185,223,240);
0xb9dff0

To assign this color to a PtWindow named win, and then test the variable, we would do this:

Gamma> win.color = PgRGB(185,223,240);
0xb9dff0;
Gamma> win.color;
0xb9dff0

In this example, the red value of 185 is 0xb9, the green value of 223 is 0xdf, and the blue value of 240 is 0xf0. To demonstrate this, we can call the functions PgRedValue, PgGreenValue, and PgBlueValue on the win.color variable to return the values for their respective bits:

Gamma> PgRedValue(win.color);
0xb9
Gamma> PgGreenValue(win.color);
0xdf
Gamma> PgBluePValue(win.color);
0xf0
[Note]

Transparent Although we said that colors in Gamma are represented with 24 bits, internally they actually are stored as 32 bit numbers. The first 8 bits are always ignored, however, except in one case--the non-color: transparent, which is represented as 0xffffffff (all 32 bits are on).