Setfillstyle() Function

setfillstyle() function sets the current fill pattern and fill color.

Declaration

void setfillstyle( int pattern, int color);
  • setfillstyle() function contains two arguments pattern and color. Various fill patterns are already enumerated in graphics.h header file as given below:
  • enum fill_styles

    {

    EMPTY_FILL,

    SOLID_FILL,

    LINE_FILL,

    LTSLASH_FILL,

    SLASH_FILL,

    BKSLASH_FILL,

    LTBKSLASH_FILL,

    HATCH_FILL,

    XHATCH_FILL,

    INTERLEAVE_FILL,

    WIDE_DOT_FILL,

    CLOSE_DOT_FILL,

    USER_FILL

    };

  • There are various colors that are also mentioned in graphics.h header file and 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).
  • For better understanding go through the program:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm,bkcolor;

initgraph(&gd,&gm," ");

setfillstyle(EMPTY_FILL,YELLOW);

bar3d(2,150,100,200,25,1);

setfillstyle(SOLID_FILL,RED);

bar3d(150,150,250,200,25,1);

setfillstyle(LINE_FILL,BLUE);

bar3d(300,150,400,200,25,1);

setfillstyle(LTSLASH_FILL,GREEN);

bar3d(450,150,550,200,25,1);

setfillstyle(SLASH_FILL,CYAN);

bar3d(2,250,100,300,25,1);

setfillstyle(BKSLASH_FILL,BROWN);

bar3d(150,250,250,300,25,1);

setfillstyle(LTBKSLASH_FILL,MAGENTA);

bar3d(300,250,400,300,25,1);

setfillstyle(HATCH_FILL,LIGHTRED);

bar3d(450,250,550,300,25,1);

setfillstyle(XHATCH_FILL,DARKGRAY);

bar3d(2,350,100,400,25,1);

setfillstyle(INTERLEAVE_FILL,YELLOW);

bar3d(150,350,250,400,25,1);

setfillstyle(WIDE_DOT_FILL,LIGHTMAGENTA);

bar3d(300,350,400,400,25,1);

setfillstyle(CLOSE_DOT_FILL,LIGHTGRAY);

bar3d(450,350,550,400,25,1);

getch();

closegraph();

}

The above program will display various filled rectangular bar at different-different positions with different fill patterns and fill colors. These fill patters and fill colors are set by the setfillstyle() function. The output of the above program is given below:

Output

c graphics