You are on page 1of 2

#include<stdio.

h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
int x_stack[10000],y_stack[10000];
int top1=-1,top2=-1;

void push_x(int data) //for x coordinate of seedpixel


{
top1 = top1 + 1;
x_stack[top1] = data;
}
void push_y(int data) //for y coordinate of seedpixel
{
top2 = top2 + 1;
y_stack[top2] = data;
}

int pop1() //for x coordinate of seed pixel


{
int data;
data = x_stack[top1];
top1 = top1 - 1;
return data;
}

int pop2() //for y coordinate of seedpixel


{
int data;
data = y_stack[top2];
top2 = top2 - 1;
return data;
}

void polyfill(int x,int y,int bgcolor, int fillcolor)


{
int flag=1;

while(flag==1)
{
if(getpixel(x,y)==bgcolor)
{
putpixel(x,y,fillcolor);
if(getpixel(x+1,y)==bgcolor)
{
push_x(x+1);
push_y(y);

}
if(getpixel(x,y+1)==bgcolor)
{
push_x(x);
push_y(y+1);
}
if(getpixel(x-1,y)==bgcolor)
{
push_x(x-1);
push_y(y);
}
if(getpixel(x,y-1)==bgcolor)
{
push_x(x);
push_y(y-1);
}
}
else
{
flag=0;
}

x=pop1();

y=pop2();
delay(2);

}
}

int main()
{
int bgcolor=0;
int fillcolor=12;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
rectangle(150,150,200,200);
polyfill(170,170,bgcolor,fillcolor);
getch();
closegraph();
return 0;
}

You might also like