C++ Programming Code Examples
Learn C++ Language
setfillstyle() Function in C++ Programming Language
setfillstyle() Function in C++
The header file graphics.h contains setfillstyle() function which sets the current fill pattern and fill color. Current fill pattern and fill color is used to fill the area. setfillstyle sets the current fill pattern and fill color.
To set a user-defined fill pattern, do not give a pattern of 12 (USER_FILL) to setfillstyle; instead, call setfillpattern.
Syntax for setfillstyle() Function in C++
#include<graphics.h>
void setfillstyle(int pattern, int color);
color
Specify the color
• 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
pattern
Specify the pattern
• EMPTY_FILL – 0
• SOLID_FILL – 1
• LINE_FILL – 2
• LTSLASH_FILL – 3
• SLASH_FILL – 4
• BKSLASH_FILL – 5
• LTBKSLASH_FILL – 6
• HATCH_FILL – 7
• XHATCH_FILL – 8
• INTERLEAVE_FILL – 9
• WIDE_DOT_FILL – 10
• CLOSE_DOT_FILL – 11
• USER_FILL – 12
If invalid input is passed to setfillstyle, graphresult returns -1(grError), and the current fill pattern and fill color remain unchanged.
The EMPTY_FILL style is like a solid fill using the current background color (which is set by setbkcolor).
This function does not return any value.
/* The header file graphics.h contains setfillstyle() function which sets the current fill pattern and fill color. floodfill() function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the area. */
#include <graphics.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;
// initgraph initializes the
// graphics system by loading
// a graphics driver from disk
initgraph(&gd, &gm, " ");
// center and radius of circle
int x_circle = 250;
int y_circle = 250;
int radius=100;
// setting border color
int border_color = WHITE;
// set color and pattern
setfillstyle(HATCH_FILL,RED);
// x and y is a position and
// radius is for radius of circle
circle(x_circle,y_circle,radius);
// fill the color at location
// (x, y) with in border color
floodfill(x_circle,y_circle,border_color);
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system
closegraph();
return 0;
}
Program Declares the array of five element & the elements of that array are accessed using pointer. The five elements are entered by the user and stored in the integer array data. And
Program print all the possible combination of each length from the given array in gray code order. The 'time complexity' of this algorithm is 'O(n*(2^n))'. This algorithm takes the input
Enter the two number, to find the HCF and LCF of the given two number to display the value of the HCF and LCM of the 2 numbers on the output screen as shown here in code