Friday, 27 September 2013

Boundary Fill


#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
#include<dos.h>
void bfill(int x,int y,int a);
int main()
{
   /* request auto detection */
   int gdriver = DETECT, gmode;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");

   /*Initialize the variables and accept data*/
   int r,xc,yc,x,y,p;
   cout<<"Enter the radius:";
   cin>>r;
   cout<<"Enter the center co-ordinates:";
   cin>>xc>>yc;
   x=0;

   y=r;
   p=1-r;

   /*Calculate and plot the points*/
   do
   {
    putpixel(xc+x,yc+y,WHITE);
    putpixel(xc+y,yc+x,WHITE);
    putpixel(xc-y,yc+x,WHITE);
    putpixel(xc+x,yc-y,WHITE);
    putpixel(xc-x,yc-y,WHITE);
    putpixel(xc-y,yc-x,WHITE);
    putpixel(xc+y,yc-x,WHITE);
    putpixel(xc-x,yc+y,WHITE);
    if(p<0)
    {
     x=x+1;
     y=y;
     p=p+(2*x)+1;
    }
   else
   {
    x=x+1;
    y=y-1;
    p=p+
    (2*x)+1-(2*y);
   }
  }
  while(x<=y);
  //start boundary filling
  bfill(xc,yc,4);
   /* clean up */
   getch();
   closegraph();
   return 0;
   }
void bfill(int x,int y,int a)
{int current;
 current=getpixel(x,y);
 if((current!=a)&&(current!=WHITE))
 {
 putpixel(x,y,a);
 delay(5);
 bfill(x+1,y,a);
 bfill(x-1,y,a);
 bfill(x,y+1,a);
 bfill(x,y-1,a);
 }
}
Jerrin Andrei Web Developer

No comments:

Post a Comment

Total Pageviews

DjKiRu Initative. Powered by Blogger.