Flood Fill Function In C Programming
C Graphics
First approach
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int main()
{
int gd=DETECT,gm=1;
initgraph(&gd,&gm,"c://turboc3//bgi");
setfillstyle(SOLID_FILL,RED);
circle(80,303,50);
floodfill(80,303,WHITE);
rectangle(100,200,120,220);
floodfill(110,210,WHITE);
getch();
closegraph();
return 0;
}
Second Approach
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void flood(int x,int y,int RED,int BLACK)
{
if(getpixel(x,y)==BLACK)
{
putpixel(x,y,RED);
flood(x+1,y,RED,BLACK);
flood(x-1,y,RED,BLACK);
flood(x,y+1,RED,BLACK);
flood(x,y-1,RED,BLACK);
}
}
int main()
{
int gd=DETECT,gm=0,i,j,x1,x,y,y1,x2,y2;
initgraph(&gd,&gm,"c://turboc3//bgi");
setcolor(GREEN);
rectangle(100,200,150,250);
circle(80,303,50);
flood(x=120,y=220,RED,BLACK);
getch();
closegraph();
return 0;
}
0 Comments