C++ Program to implement boundary fill algorithm

Start at a point inside the figure and paint with a particular color. Filling continues until a boundarycolor is encountered. Thjere are two ways to do this: 

Programs

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

void bfill(int x,int y,int fill,int border)
{
if((getpixel(x,y)!=border)&&(getpixel(x,y)!=fill))
{
delay(8);
putpixel(x,y,fill);

bfill(x+1, y,fill,border);
        bfill(x, y+1,fill,border);
        bfill(x-1, y,fill,border);
        bfill(x, y-1,fill,border);        
}
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
rectangle(10,50,50,10);
bfill(11,12,MAGENTA,WHITE);
getch();
closegraph();
}

0 comments:

Post a Comment