Friday, September 15, 2017

SEED FILL Algorithm

SEED FILL Algorithm


#include<stdio.h>
#include<graphics.h>
void right_fill(int x, int y);
void left_fill(int x, int y);
int main()
{
 int gd=DETECT, gm,op,i,x,y,n,a[10][3];
   printf(" Enter no. of vertices : ");
 scanf("%d", &n);
 for(i=0;i<n;i++)
    {
     printf(" Enter the co-ordinates : ");
     scanf("%d%d", &a[i][0], &a[i][1]);
    }
    printf(" Enter seeding point : ");
    scanf("%d%d", &x, &y);
    initgraph(&gd, &gm, NULL);
    for(i=0;i<n;i++)
    {
     line(a[i][0], a[i][1], a[(i+1)%n][0], a[(i+1)%n][1]);
    }
    right_fill(x,y);
    left_fill(x-1,y);
    getch();
}
 void right_fill(int x, int y)
 {
  while((getpixel(x,y)!=WHITE) && (getpixel(x,y)!=RED))
  {
   delay(1);
   putpixel(x,y,RED);
   right_fill(++x,y);
   x=x-1;
   right_fill(x,y-1);
   right_fill(x,y+1);
  }
 }
 void left_fill(int x, int y)
 {
  while((getpixel(x,y)!=WHITE) && (getpixel(x,y)!=RED))
  {
   delay(1);
   putpixel(x,y,RED);
   left_fill(--x,y);
   x=x+1;
   left_fill(x,y-1);
   left_fill(x,y+1);
  }
 }

download file now

No comments:

Post a Comment

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