C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 4 WAY BOUNDARY FILLING ALGORITHM
C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 4 WAY BOUNDARY FILLING ALGORITHM
CODE:
// C Implementation for 4 way Boundary Filling Algorithm
#include<graphics.h>
#include<stdlib.h>
#include<iostream>
#include<conio.h>
int main()
{
void boundary_fill(int x,int y,int f,int b);
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
setcolor(getmaxcolor());
int points[]={50,50,50,100,100,150,150,100,200,200,250,100,250,50,50,50};
drawpoly(8, points);
boundary_fill(100,100,4,15);
getch();
closegraph();
return 0;
}
void boundary_fill(int x,int y,int f,int b)
{
if(getpixel(x,y)!=b && getpixel(x,y)!=f)
{
putpixel(x,y,f);
boundary_fill(x+1,y,f,b);
boundary_fill(x-1,y,f,b);
boundary_fill(x,y+1,f,b);
boundary_fill(x,y-1,f,b);
}
}
OUTPUT:
Comments
Post a Comment