C++ Program to implement flood fill algorithm (graphics)

Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array. It is used in the "bucket" fill tool of paint programs to fill connected, similarly-colored areas with a different color, and in games such as Go and Minesweeper for determining which pieces are cleared. When applied on an image to fill a particular bounded area with color, it is also known as boundary fill.

Program

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
void ffill(int x,int y,int fill,int old)
{
if((getpixel(x,y)!=old)&&(getpixel(x,y)!=fill))
{
delay(8);
putpixel(x,y,fill);
ffill(x+1,y,fill,old);
ffill(x-1,y,fill,old);
ffill(x,y+1,fill,old);
ffill(x,y-1,fill,old);
}
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
rectangle(10,50,50,10);
ffill(15,30,MAGENTA,WHITE);
getch();
closegraph();
}

0 comments:

Post a Comment