Search code examples
cflood-fillbgiturbo-c

Flood fill difficulty in C graphics


(Note: My college is making me study graphics in ancient Turbo C)

Anyway I am using the inbuilt algorithm for floodfill to color a well and a bucket.

The problem I am facing is that the compiler fills the region upto a boundary color. However I would like to fill a basic figure (eliipse here) irrespective of the boundary. How will one do that?

I did some testing as shown below,

enter image description here

Pic1, Filled bucket before drawing well, So well draws over the blue
Pic2, Drew well before flood filling bucket, So fills only one part

My Code:

#include<graphics.h>
#include<stdio.h>
void well()
{
    ellipse(50,150,0,360,50,20); //Hole of the well
    arc(50,120,180,300,100);
    line(0,150,0,206);
    line(100,150,100,206);

    line(0,150,0,100);
    line(0,100,50,100);
    circle(50,100,10);

    setfillstyle(SOLID_FILL,RED);
    floodfill(20,170,WHITE);
}
void bucket(int j)
{
    ellipse(50,j,0,360,20,10);    //The Ellipse to be filled as blue
    line(40,j+40,60,j+40);
    line(40,j+40,30,j);
    line(60,j+40,70,j);
    setfillstyle(SOLID_FILL,BLUE);
    floodfill(50,j,WHITE);
}
void main()
{
    int gdriver = DETECT, gmode,i;
    initgraph(&gdriver, &gmode, "C:\\TC\\BGI");

    cleardevice();

    well();
    bucket(130);

    getch();
}

Solution

  • Use fillellipse() instead of ellipse().