• Have Any Question?
  • contact@eitworld.com

Setcolor() Function





  • setcolor() function is used to set the foreground color in graphics mode. After resetting the foreground color you will get the text or any other shape which you want to draw in that color. Each color is assigned a number.
  • The possible color values are from 0 – 15 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).

Declaration

void setcolor(int color);
  • setcolor() functions contains only one argument that is color. It may be the color name enumerated in graphics.h header file or number assigned with that color.
  • For better understanding go through the program:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,” “);

setcolor(GREEN);

circle(320,240,100);

setcolor(RED);

outtextxy(320,80.”It is circle”);

getch();

closegraph();

}

Above program will print a circle of green color containing 100cm radius at position (320,240) and also a text of red color at position (320,80) on execution. The output of the above program is shown below:

Output

c graphics



Real Time Web Analytics