user3382203
user3382203

Reputation: 179

C: Using floodfill to fill a circle

Whenever I execute this code below, the whole screen fills up with a grid pattern in red. I just want to fill the circular region in red.

#include<graphics.h>
#include<conio.h>
void main(){
    int gm, gd=DETECT;
    initgraph(&gd,&gm,"c:\\turboC3\\bgi");
    circle(100,100,50);
    setfillstyle(HATCH_FILL,RED);
    floodfill(100,100,RED);
    getch();
    closegraph();
}

Output:

enter image description here

Upvotes: 4

Views: 27960

Answers (1)

shauryachats
shauryachats

Reputation: 10405

In the line floodfill(100,100,RED), the third parameter has to be the color of the border. As by default, your circle's border color is WHITE, so change your code to:

#include<graphics.h>
#include<conio.h>
void main(){
    int gm, gd=DETECT;
    initgraph(&gd,&gm,"c:\\turboC3\\bgi");
    circle(100,100,50);
    setfillstyle(HATCH_FILL,RED);
    //Change RED to WHITE.
    floodfill(100,100,WHITE);
    getch();
    closegraph();
}

Thanks to you, I learnt a new thing today. :)

Upvotes: 6

Related Questions