setcolor function of c graphic is used set the foreground color in graphics mode. To get the maximumnumber of colors we need to use getmaxcolor() function.
#include <graphics.h>
#include <stdio.h>
int main( )
{
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\tc\\bgi");
setcolor(9);
rectangle(100,80,400,200);
line(100,220,400,220);
setcolor(11);
outtextxy(100,240,"demo of setcolor");
getch();
closegraph();
return 0;
}
General syntax of setcolor function is :
setcolor(int color);
In setcolor function of c graphic forecolor set by its name or its integer value. There are following colors available in setcolor function with its corresponding integer value.
Color | int value |
---|---|
BLACK | 0 |
BLUE | 1 |
GREEN | 2 |
CYAN | 3 |
RED | 4 |
MAGENTA | 5 |
BROWN | 6 |
LIGHTGRAY | 7 |
DARKGRAY | 8 |
LIGHTBLUE | 9 |
LIGHTGREEN | 10 |
LIGHTCYAN | 11 |
LIGHTRED | 12 |
LIGHTMAGENTA | 13 |
YELLOW | 14 |
WHITE | 15 |
After set the foreground color the text, line or rectangle will be drawn on the recent set color.
C graphic program to demonstrate setcolor function
#include <graphics.h>
#include <stdio.h>
int main( )
{
int gd=DETECT, gm;
initgraph(&gd,&gm,"C:\\tc\\bgi");
setcolor(9);
rectangle(100,80,400,200);
line(100,220,400,220);
setcolor(11);
outtextxy(100,240,"demo of setcolor");
getch();
closegraph();
return 0;
}
Download |
---|
0 comments:
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.