Tuesday, April 13, 2010

FloodFill Algo

#include
#include
#include
#include
void main()
{
 int l,t,r,b,gd=DETECT,x,y,gm,fc;
  void floodfill2(int,int,int,int);
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 printf("Enter the left top and right bottom of the rectanlge:\n");
 scanf("%d%d%d%d",&l,&t,&r,&b);
 rectangle(l,t,r,b);
 printf("Enter the inside pixel");
 scanf("%d%d",&x,&y);
 floodfill2(x,y,6,0);
 getch();
}

 void floodfill2(int x,int y,int fc,int oc)
 {
  int c=getpixel(x,y);
  if(c==oc)
  {
  putpixel(x,y,fc);
   floodfill2(x+1,y,fc,oc);
   floodfill2(x-1,y,fc,oc);
   floodfill2(x,y+1,fc,oc);
   floodfill2(x,y-1,fc,oc);
  }
 }

0 comments:

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase