setcolor function in c graphics

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.

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.

Colorint value
BLACK0
BLUE1
GREEN2
CYAN3
RED4
MAGENTA5
BROWN6
LIGHTGRAY7
DARKGRAY8
LIGHTBLUE9
LIGHTGREEN10
LIGHTCYAN11
LIGHTRED12
LIGHTMAGENTA13
YELLOW14
WHITE15

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;
}



setcolor function of c graphics

Download


0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.