setcolor function in C

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.





// C Implementation for setcolor()
#include <graphics.h>
#include <stdio.h>
// driver code
int main()
    // gm is Graphics mode which is
    // a computer display mode that
    // generates image using pixels.
    // DETECT is a macro defined in
    // "graphics.h" header file
    int gd = DETECT, gm, color;
    // initgraph initializes the
    // graphics system by loading a
    // graphics driver from disk
    initgraph(&gd, &gm, "");
    // Draws circle in white color
    // center at (100, 100) and radius
    // as 50
    circle(100, 100, 50);
    // setcolor function
    // Draws circle in green color
    // center at (200, 200) and radius
    // as 50
    circle(200, 200, 50);
    // closegraph function closes the
    // graphics mode and deallocates
    // all memory allocated by
    // graphics system .
    return 0;


Output :

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :


Please write to us at to report any issue with the above content.