Specifying colors
You specify a color by specifying a number that represents
the color. You can specify the number explicitly or by using an
expression that includes the RGB (r, g, b)
function.
For the numbers and expressions that specify common colors,
see Table 24-2.
How the number is calculated
The formula for combining color values into a number is:
|
1 |
<span>red</span> + 256*<span>green</span> + 256*256*<span>blue</span> |
where the amount of each primary color (red, green, and blue)
is specified as a value from 0 to 255.
The RGB function calculates the number
from the amounts of red, green, and blue specified.
Sample numeric calculation
To create cyan, you use blue and green, but no red. If you
wanted to create the most saturated (bright) cyan, you would use
maximum amounts of blue and green in the formula, which is indicated
by the number 255 for each. The following statements show the calculation:
|
1 |
<span>red</span> + 256*<span>green</span> + 256*256*<span>blue</span> |
|
1 |
0 + 256*<span>255</span> + 256*256*<span>255</span> |
|
1 |
0 + 65280 + 16711680 |
|
1 |
16776960 |
Sample expression using the RGB function
The following expression specifies the brightest cyan:
|
1 |
RGB (<span>0</span>,<span>255</span>,<span>255</span>) |
Notice that the expression specifies the maximum for green
and blue (255) and 0 for red. The expression returns the value 16776960.
To specify cyan, entering the expression RGB(0, 255, 255)
is the same as entering the number 16776960.
Numbers and expressions to enter for the common
colors
Table 24-2 shows
the numbers and expressions to enter for some common colors. The
number and expression for a color are equivalent. You can use either.
|
Color |
Expression |
Number to |
How |
|---|---|---|---|
|
Black |
RGB (0, 0, 0) |
0 |
0 (no color) |
|
Blue |
RGB (0, 0, 255) |
16711680 |
256*256*255 (blue only) |
|
Cyan |
RGB (0, 255, 255) |
16776960 |
256*255 + 256*256*255 |
|
Dark Green |
RGB (0, 128, 0) |
32768 |
256*128 (green only) |
|
Green |
RGB (0, 255, 0) |
65280 |
256*255 (green only) |
|
Light Gray |
RGB (192, 192, 192) |
12632256 |
192 + 256*192 + 256*256*192 |
|
Lighter Gray |
RGB (224, 224, 224) |
14737632 |
224 + 256*224 + 256*256*224 |
|
Lightest Gray |
RGB (240, 240, 240) |
15790320 |
240 + 256*240 + 256*256*240 |
|
Magenta |
RGB (255, 0, 255) |
16711935 |
255 + 256*256*255 |
|
Red |
RGB (255, 0, 0) |
255 |
255 (red only) |
|
White |
RGB (255, 255, 255) |
16777215 |
255 + 256*255 + 256*256*255 |
|
Yellow |
RGB (255, 255, 0) |
65535 |
255 + 256*255 (red |