C语言 C: 使用 floodfill 来填充一个圆圈
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27885110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C: Using floodfill to fill a circle
提问by user3382203
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:
输出:


回答by shauryachats
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:
在该行中floodfill(100,100,RED),第三个参数必须是边框的颜色。默认情况下,您圆圈的边框颜色为WHITE,因此请将您的代码更改为:
#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. :)
多亏了你,我今天学到了新东西。:)

