Fill A Circle Using Flood Fill Algorithm
INPUT
#include<conio.h>
#include<graphics.h>
void floodFill(int, int, int, int);
int midx=319, midy=239;
void main()
{
int gdriver=DETECT, gmode, x,y,r;
initgraph(&gdriver, &gmode, "C:\\TURBOCS3\\BGI");
cleardevice();
printf("Enter the Center of circle (X,Y) : ");
scanf("%d %d",&x,&y);
printf("Enter the Radius of circle R : ");
scanf("%d",&r);
circle(midx+x,midy-y,r);
getch();
floodFill(midx+x,midy-y,13,0);
getch();
closegraph();
}
void floodFill(int x, int y, int fill, int old)
{
if(getpixel(x,y) == old)
{
putpixel(x,y,fill);
delay(5);
floodFill(x+1,y,fill,old);
floodFill(x-1,y,fill,old);
floodFill(x,y+1,fill,old);
floodFill(x,y-1,fill,old);
}
}
OUTPUT
Post a Comment