Wednesday 28 October 2015

Flood Fill Algorithm in C++(Source Code)

/*Flood Fill Algorithm*/

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

void floodFill(int x, int y, int old, int fill)
{
int current;
current=getpixel(x,y);
if(current==old)
{
putpixel(x,y,fill);
delay(1);
floodFill(x+1,y,old,fill);
floodFill(x-1,y,old,fill);
floodFill(x, y+1,old,fill);
floodFill(x,y-1,old,fill);
}
}

void main()
{
int o=0;
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm, "C:\\TC\\BGI");

rectangle(100,100,150,150);    //RED
rectangle(200,200,250,250);    //MAGENTA
rectangle(300,100,350,150);    //BROWN
rectangle(400,200,450,250);    //LIGHTGRAY

floodFill(125,125,o,4);        //RED
floodFill(225,225,o,5);        //MAGENTA
floodFill(325,125,o,6);        //BROWN
floodFill(425,225,o,7);        //LIGHTGRAY

getch();
closegraph();
}

For OUTPUT check out the video! :


No comments:

Post a Comment