• Have Any Question?
  • contact@eitworld.com

Floodfill() Function





floodfill() function is used to fill an enclosed area with current fill pattern and fill color.

void floodfill(int x, int y, int border);
  • (x,y) is an point on the screen. If this point is present inside the enclosed area then the interior of the area is filled by the current fill pattern and fill color and if point is present outside the enclosed area then the exterior of the enclosed area is filled by the current fill pattern and fill color.
  • border specifies the color of border of the enclosed area.
  • floodfill() function fills an area with the desired color in all directions until it could see the border color.
  • For better understanding go through the programs:

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm;

initgraph(&gd,&gm,” “);

setcolor(RED);

rectangle(100,200,200,275);

floodfill(101,201,RED);

getch();

closegraph();

}

In this program we draw a rectangle of length 100 cm and breadth 75 cm. Then we are going to fill a current fill color inside the rectangle. For this we take the point (101, 201) as the parameter of floodfill function that is present inside the rectangle so whole area present inside the rectangle will fill by the default fill color that is white. We can change the current fill color with the setfillstyle() function and border color of rectangle is red so it fills with the desired color in all directions until it could see the border color (that is red).

Output

floodfill

Program2: When point present outside the enclosed area:

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm;

initgraph(&gd,&gm,” “);

setcolor(RED);

rectangle(100,200,200,275);

floodfill(0,50,RED);

getch();

closegraph();

}

In this program we draw a rectangle of length 100 cm and breadth 75 cm. Then we are going to fill a current fill color outside the rectangle. For this we take the point (0, 50) as the parameter of floodfill function that is present outside the rectangle so whole area present outside the rectangle will fill by the default fill color that is white. We can change the current fill color with the setfillstyle() function and border color of rectangle is red so it fills with the desired color in all directions until it could see the border color (that is red).

Output

floodfill



Real Time Web Analytics