20 Feb 2013

C/C++ programs for boundary fill with 4 connect


C/C++ programs for boundary fill with 4 connect 

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void b_fill(int x,int y,int newc,int boundc)
{
          int g;
          g=getpixel(x,y);
          if((g!=boundc)&&(g!=newc))
          {

                   putpixel(x,y,newc);
                   delay(1);
                   b_fill(x+1,y,newc,boundc);
                   //b_fill(x-1,y,newc,boundc);
                   b_fill(x,y-1,newc,boundc);
                    b_fill(x,y+1,newc,boundc);     
          }
}

void main()
{
          int gd=DETECT,gm;
          initgraph(&gd,&gm,"C:\\tc\\bgi");
          rectangle(50,50,150,150);
          b_fill(51,51,GREEN,WHITE);
          rectangle(150,150,250,250);
          b_fill(151,151,RED,WHITE);
          rectangle(250,250,350,350);
          b_fill(251,251,BLUE,WHITE);
          getch();
}

OUTPUT:

1 comment:

  1. If I take a point somewhere in the middle of a rectangle, and uncomment the lines in the b_fill function, it is not working. Can you see to that?

    ReplyDelete