If you have a VGA machine, you are restricted to displaying at most 256 colors at a time. These 256 colors are held in a palette. You can choose the palette colors from a range of 262,144 colors (256K), but only 256 at a time. Some display adapters (most SVGAs) are capable of displaying all of the 256K colors and some (true color display adapters) are capable of displaying 256 * 256 * 256 = 16.7 million colors.
If you use a palette, you are restricted to the colors available in the palette. In order to access all colors available on your system, you need to specify an explicit Red-Green-Blue (RGB) value, not a palette index.
When you select a color index, you specify one of the colors in the system's predefined palette.
set the current color, background color, and text color to a palette index.
set the colors to a color value chosen from the entire available range. When you select a color value, you specify a level of intensity with a range of 0 - 255 for each of the red, green, and blue color values. The long integer that defines a color value consists of 3 bytes (24 bits) as follows:
BBBBBBBB GGGGGGGG RRRRRRRR
where R, G, and B represent the bit values for red, green, and blue intensities. To mix a light red (pink), turn red all the way up and mix in some green and blue:
10000000 10000000 11111111
In hexadecimal notation, this number equals #8080FF. To set the current color to this value, you can use the function:
i = SETCOLORRGB (#8080FF)
You can also pass decimal values to this function. Keep in mind that 1 (binary 00000001, hex 01) represents a low color intensity and that 255 (binary 11111111, hex FF) equals full color intensity. To create pure yellow (100-percent red plus 100-percent green) use this line:
i = SETCOLORRGB( #00FFFF )
For white, turn all of the colors on:
i = SETCOLORRGB( #FFFFFF)
For black, set all of the colors to 0:
i = SETCOLORRGB( #000000)
RGB values for example colors are in the following table.
If you have a 64K-color machine and you set an RGB color value that is not equal to one of the 64K preset RGB color values, the system approximates the requested RGB color to the closest available RGB value. The same thing happens on a VGA machine when you set an RGB color that is not in the palette. (You can remap your VGA color palette to different RGB values; see VGA Color Palette
However, although your graphics are drawn with an approximated color, if you retrieve the color with
, the color you specified is returned, not the actual color used. This is because the
functions do not execute any graphics, they simply set the color and the approximation is made when the drawing is made (by
, for example).
do return the approximated color actually used, because
actually set a pixel to a color on the screen and the approximation, if any, is made at the time they are called.