C++ PROGRAM TO IMPLEMEMT THE CONCEPT OF FLOODFILL ALGORITHM
C++ PROGRAM TO IMPLEMEMT THE CONCEPT OF FLOODFILL ALGORITHM
CODE:
// program to fill a polygon using floodfill algorithm
#include <graphics.h>
#include <stdio.h>
void flood(int x, int y, int new_col, int old_col)
{
if (getpixel(x, y) == old_col) {
putpixel(x, y, new_col);
flood(x + 1, y, new_col, old_col);
flood(x - 1, y, new_col, old_col);
flood(x, y + 1, new_col, old_col);
flood(x, y - 1, new_col, old_col);
}
}
int main()
{
int gd, gm = DETECT;
initgraph(&gd, &gm, "");
int top, left, bottom, right;
top = left = 50;
bottom = right = 300;
int points[]={50,50,50,100,100,150,150,100,200,200,250,100,250,50,50,50};
drawpoly(8, points);
int x = 51;
int y = 51;
int newcolor = 12;
int oldcolor = 0;
flood(x, y, newcolor, oldcolor);
getch();
return 0;
}
OUTPUT:
Comments
Post a Comment