setcolor function in C
Last Updated :
23 Jan, 2018
The header file graphics.h contains setcolor() function which is used to set the current drawing color to the new color.
Syntax :
void setcolor(int color);
Explanation : In Graphics, each color is assigned a number. Total number of colors available are 16. Number of available colors depends on current graphics mode and driver. For example, setcolor(RED) or setcolor(4) changes the current drawing color to RED. Remember that default drawing color is WHITE. The Colors table is given below.
COLOR INT VALUES
-------------------------------
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
Below is the implementation of setcolor() function.
#include <graphics.h>
#include <stdio.h>
int main()
{
int gd = DETECT, gm, color;
initgraph(&gd, &gm, "" );
circle(100, 100, 50);
setcolor(GREEN);
circle(200, 200, 50);
getch();
closegraph();
return 0;
}
|
Output :
Share your thoughts in the comments
Please Login to comment...