Write a program to fill a circle using flood fill algorithm


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

void floodFill(int, int, int, int);
int midx=319, midy=239;

void main()
{
      int gdriver=DETECT, gmode, x,y,r;
      initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

      cleardevice();

      printf("Enter the Center of circle (X,Y) : ");
      scanf("%d %d",&x,&y);
      printf("Enter the Radius of circle R : ");
      scanf("%d",&r);

      circle(midx+x,midy-y,r);
      getch();
      floodFill(midx+x,midy-y,13,0);

      getch();
      closegraph();
}

void floodFill(int x, int y, int fill, int old)
{
      if(getpixel(x,y) == old)
      {
            putpixel(x,y,fill);
            delay(5);
            floodFill(x+1,y,fill,old);
            floodFill(x-1,y,fill,old);
            floodFill(x,y+1,fill,old);
            floodFill(x,y-1,fill,old);
      }
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP