C Program for Boundary Fill Algorithm To Fill Different Types Of Geometric Shapes

Ram Pothuraju
#include< stdio.h>
#include< conio.h>
#include< graphics.h>
void BoundaryFill4(int,int,int,int);
void BoundaryFill8(int,int,int,int);
void main()
{
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"");

 setbkcolor(15);
 setcolor(BLUE);
 outtextxy(0,0,"Boundary Filling algorithm using 4-connected and 8-connected");
 rectangle(50,50,100,100);
 circle(50,50,30);
 BoundaryFill8(56,56,5,BLUE);
 BoundaryFill4(40,40,14,BLUE);

getch();
}
void BoundaryFill4(int x,int y,int fill,int boundary)
{
 int current;
 current=getpixel(x,y);
 if((current!=boundary) && (current!=fill))
 {
  putpixel(x,y,fill);
  BoundaryFill4(x+1,y,fill,boundary);
  BoundaryFill4(x-1,y,fill,boundary);
  BoundaryFill4(x,y-1,fill,boundary);
  BoundaryFill4(x,y+1,fill,boundary);
 }
}
void BoundaryFill8(int x,int y,int fill,int boundary)
{
 int current;
 current=getpixel(x,y);
 if((current!=boundary) && (current!=fill))
 {

  putpixel(x,y,fill);
  BoundaryFill8(x+1,y,fill,boundary);
  BoundaryFill8(x-1,y,fill,boundary);
  BoundaryFill8(x,y-1,fill,boundary);
  BoundaryFill8(x,y+1,fill,boundary);
  BoundaryFill8(x+1,y+1,fill,boundary);
  BoundaryFill8(x-1,y+1,fill,boundary);
  BoundaryFill8(x-1,y-1,fill,boundary);
  BoundaryFill8(x+1,y-1,fill,boundary);
 }
}

OUTPUT




Post a Comment

0Comments

Post a Comment (0)