Sunday, 23 March 2014

Flood Fill Algorithm Using C

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<dos.h>

void flood(int,int,int);

void main()
{

int gd=DETECT,gm;
int ch,x,y,bc,fc;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
printf("Enter boundry color:");
scanf("%d",&bc);
setcolor(bc);
rectangle(250,200,300,250);
x=280;
y=240;
flood(x,y,bc);
getch();
closegraph();
}
void flood(int x,int y,int bc)
{
if(getpixel(x,y)!=bc)
{
putpixel(x,y,bc);
flood(x+1,y,bc);
flood(x,y+1,bc);
flood(x-1,y,bc);
flood(x,y-1,bc);
}
}

No comments:

Post a Comment