Skip to content

Instantly share code, notes, and snippets.

@synsh
Created January 20, 2017 17:36
Show Gist options
  • Save synsh/f9e5f39aa6b4ed682ff0835322b4f05f to your computer and use it in GitHub Desktop.
Save synsh/f9e5f39aa6b4ed682ff0835322b4f05f to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<graphics.h>
void flood_fill(int x,int y,int old_color,int fill_color);
int main()
{
int gd,gm,x,y,x1,x2,y1,y2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C://TurboC3//BGI");
printf("Enter top-left point of rectangle: ");
scanf("%d%d",&x1,&y1);
printf("Enter bottom-right point of rectangle: ");
scanf("%d%d",&x2,&y2);
cleardevice();
setcolor(WHITE);
rectangle(x1,y1,x2,y2);
flood_fill(x1+1,y1+1,0,4);
getch();
closegraph();
return 0;
}
void flood_fill(int x,int y,int old_color,int fill_color)
{
int current;
current=getpixel(x,y);
if(current==old_color)
{
putpixel(x,y,fill_color);
delay(10);
flood_fill(x+1,y,old_color,fill_color);
flood_fill(x,y+1,old_color,fill_color);
flood_fill(x-1,y,old_color,fill_color);
flood_fill(x,y-1,old_color,fill_color);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment