Monday, May 2, 2011

BOUNDARY FILL GRAPHICS PROGRAM IN C



#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void boundaryfill(int,int,int,int);
int main()
{
  int xc,yc,r,fc,bc;
  int gd=DETECT,gm;
  initgraph(&gd,&gm," ");
  printf("\n\n Enter xc:");
  scanf("%d",&xc);
  printf("\n\n Enter yc:");
  scanf("%d",&yc);
  printf("\n\n Enter r:");
  scanf("%d",&r);
  setcolor(8);
  circle(xc,yc,r);
  printf("\n\n Enter fill color:");
  scanf("%d",&fc);
  printf("\n\n Enter Boundary Color");
  scanf("%d",&bc);
 
  boundaryfill(xc,yc,fc,bc);
  getch();
  closegraph();
  return 0;
}



void boundaryfill(int x1,int y1,int fc1,int bc1)
{
  int current;
  current=getpixel(x1,y1);
  printf("\n\n %d",current);
  if((current !=bc1) && (current != fc1))
  {
     setcolor(fc1);
     putpixel(x1,y1,9);
     boundaryfill(x1+1,y1,fc1,bc1);
     boundaryfill(x1-1,y1,fc1,bc1);
     boundaryfill(x1,y1+1,fc1,bc1);
     boundaryfill(x1,y1-1,fc1,bc1);
   }
}


1 comment: