简体   繁体   中英

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:

在此输入图像描述

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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM