#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void boundaryfill(int x,int y,int fcolor,int bcolor);
void main()
{ clrscr();
int gd,gm;
gd=DETECT;
gm=0;
initgraph(&gd,&gm,"Z:\TC\BGI");
int x,y,bcolor,fcolor;
cout<<"enter seed point";
cin>>x>>y;
cout<<"enter boundary color";
cin>>bcolor;
cout<<"enter new color";
cin>>fcolor;
setcolor(bcolor);
rectangle(50,50,100,100);
boundaryfill(x,y,fcolor,bcolor);
getch();
}
void boundaryfill(int x,int y,int fcolor,int bcolor)
{
if((getpixel(x,y)!=fcolor)&&(getpixel(x,y)!=bcolor))
{ putpixel(x,y,fcolor);
boundaryfill(x+1 ,y,fcolor,bcolor);
boundaryfill(x-1,y,fcolor,bcolor);
boundaryfill(x,y-1,fcolor,bcolor);
boundaryfill(x,y+1,fcolor,bcolor);
boundaryfill(x+1,y-1,fcolor,bcolor);
boundaryfill(x+1,y+1,fcolor,bcolor);
boundaryfill(x-1,y-1,fcolor,bcolor);
boundaryfill(x-1,y+1,fcolor,bcolor);
}
}
0 comments :