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
the following table.
How the number is
calculated
The formula for combining color values into a number is:
|
1 |
red + 256*green + 256*256*blue |
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 2 3 4 |
red + 256*green + 256*256*blue 0 + 256*255 + 256*256*255 0 + 65280 + 16711680 16776960 |
Sample expression using the RGB
function
The following expression specifies the brightest cyan:
|
1 |
RGB (0,255,255) |
Notice that the expression specifies the maximum for green and
blue 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
The following table 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 to enter |
Number to enter |
How the number is calculated |
|---|---|---|---|
|
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 (green and |
|
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 (some red, green, and |
|
Lighter Gray |
RGB (224, 224, 224) |
14737632 |
224 + 256*224 + 256*256*224 (some red, green, and |
|
Lightest Gray |
RGB (240, 240, 240) |
15790320 |
240 + 256*240 + 256*256*240 (some red, green, and |
|
Magenta |
RGB (255, 0, 255) |
16711935 |
255 + 256*256*255 (red and blue) |
|
Red |
RGB (255, 0, 0) |
255 |
255 (red only) |
|
White |
RGB (255, 255, 255) |
16777215 |
255 + 256*255 + 256*256*255 (red, green, and blue |
|
Yellow |
RGB (255, 255, 0) |
65535 |
255 + 256*255 (red and green) |