Monday, July 31, 2017

SEED FILL NON RECURSIVE

SEED FILL NON RECURSIVE


#include<stdio.h>
#include<math.h>
#include<graphics.h>
struct stack
{
   long int x;
   long int y;
   struct stack *next;
}*p,*temp,*head=NULL;
typedef struct stack t1;
void push(int ,int);
void pop();
int xf,yf;
void bfillnrc(int,int,int,int);
int main()
{
  int gd=DETECT,gm;
  int xy,yc,rx,r,n,choice,ch,newcolor;
  int i,ax[200],ay[200];
  printf(" ENter the fill color:");
  scanf("%d",&newcolor);
  printf(" ENter no of sides:");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    printf(" ENter %d CO-Ordinates",i+1);
    scanf("%d%d",&ax[i],&ay[i]);
  }
printf(" ENter the inner point:");
scanf("%d%d",&xf,&yf);
initgraph(&gd,&gm,"c:/tc/bgi");
for(i=0;i<n;i++)
 {
   line(ax[i],ay[i],ax[(i+1)%n],ay[(i+1)%n]);//delay
  }
bfillnrc(xf,yf,newcolor,15);
getch();
return 0;
}
void bfillnrc(int x,int y,int newcolor,int bdry)
{
  if(getpixel(x,y)==bdry)
{
   return;
}
  push(x,y);
  putpixel(x,y,newcolor);
  while(head!=NULL)
{
  delay(1);
  pop();
  x=p->x;
  y=p->y;
if((getpixel(x+1,y)!=bdry)&&(getpixel(x+1,y)!=newcolor))
 {
   putpixel(x+1,y,newcolor);
   push(x+1,y);
}
 if((getpixel(x-1,y)!=bdry)&&(getpixel(x-1,y)!=newcolor))
  {
    putpixel(x-1,y,newcolor);
    push(x-1,y);
  }
if((getpixel(x,y+1)!=bdry)&&(getpixel(x,y+1)!=newcolor))
  {
    putpixel(x,y+1,newcolor);
    push(x,y+1);
   }
if((getpixel(x,y-1)!=bdry)&&(getpixel(x,y-1)!=newcolor))
  {
    putpixel(x,y-1,newcolor);
    push(x,y-1);
  }
 }
}
void push(int x1,int y1)
{
  temp=(t1*)malloc(sizeof(t1));
  temp->x=x1;
  temp->y=y1;
  if(head==NULL)
{
  head=temp;
  head->next=NULL;
}
else
 {
   temp->next=head;
   head=temp;
}
}
void pop()
{
  p=head;
  head=head->next;
}



download file now

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.