WAP to under stand Boundary Fill Algorithm.

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



void boundaryFill4(int x, int y, int fill, int boundary)
{
int current;
current = getpixel(x,y);

if((current!= boundary) && (current != fill))
{
setcolor(fill) ;
putpixel(x,y,fill);
boundaryFill4(x+1,y,fill,boundary);
boundaryFill4(x-1,y,fill,boundary);
boundaryFill4(x,y+1,fill,boundary);
boundaryFill4(x,y-1,fill,boundary);
}
}

void main()
{
int xc,yc,rx,ry;
int gdriver=DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver, &gmode, "C:\TURBOC3\BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setbkcolor(RED);
rectangle(50,50,100,100);
boundaryFill4(70,70,YELLOW,WHITE);
getch();
closegraph();
}

Output:
           

Comments