===== setcolor =====
====Syntax of setcolor ====
#include
void setcolor(int color);
==== Description of setcolor ====
setcolor sets the current drawing color to color, which can range from 0
to getmaxcolor. The current drawing color is the value to which pixels
are set when lines, and so on are drawn. The drawing colors shown below
are available for the CGA and EGA, respectively.
Palette Number  Three Colors
0 LIGHTGREENÂ ÂLIGHTRED YELLOW
1 LIGHTCYAN LIGHTMAGENTAÂ ÂWHITE
2 GREEN REDBROWN
3 CYAN MAGENTA LIGHTGRAY
Name Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
You select a drawing color by passing either the color number itself or
the equivalent symbolic name to setcolor. For example, in CGAC0 mode, the
palette contains four colors: the background color, light green, light
red, and yellow. In this mode, either setcolor(3) or setcolor(CGA_YELLOW)
selects a drawing color of yellow.
==== Example of setcolor ====
/* setcolor example */
#include
#include
#include
#include
int main(void)
{
/* select driver and mode that supports multiple drawing colors */
int gdriver = EGA, gmode = EGAHI, errorcode;
int color, maxcolor, x, y;
char msg[80];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* maximum color index supported */
maxcolor = getmaxcolor();
/* for centering text messages */
settextjustify(CENTER_TEXT, CENTER_TEXT);
x = getmaxx() / 2;
y = getmaxy() / 2;
/* loop through the available colors */
for (color=1; color<=maxcolor; color++) {
cleardevice(); /* clear the screen */
setcolor(color); /* select new background color */
/* output a messsage */
sprintf(msg, "Color: %d", color);
outtextxy(x, y, msg);
getch();
}
/* clean up */
closegraph();
return 0;
}
==== See also ====
[[getcolor]]
[[getmaxcolor]]
[[graphresult]]
[[setallpalette]]
[[setbkcolor]]
[[setpalette]]
===== output of setcolor example =====
no output of example at the moment
do not hesitate and add it...