Open In App
Related Articles

setcolor function in C

Improve Article
Save Article
Like Article

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 :

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 23 Jan, 2018
Like Article
Save Article
Similar Reads