/*
Title: Boundary Fill Algorithm
Description: An algorithm to fill colour in to the circle using 4 connected approach
*/
#include<stdio.h>
#include<graphics.h>
void boundaryfill(int x,int y,int f_color,int b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color) //getpixel(x,y) gives the color of seed pixel
{
//printf("%d%d", &x, &y);
putpixel(x,y,f_color); //putpixel(x,y) draws the pixel with fill colour
delay(1);
boundaryfill(x+1,y,f_color,b_color);
boundaryfill(x,y+1,f_color,b_color);
boundaryfill(x-1,y,f_color,b_color);
boundaryfill(x,y-1,f_color,b_color);
}
}
int main()
{
int gm,gd=DETECT,radius;
int x,y;
printf("Enter x and y of center point of circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
initgraph(&gd,&gm,"");
circle(x,y,radius);
boundaryfill(x,y,4,15);
// delay(1);
closegraph();
return 0;
}