#include "Conio.h"
#include "graphics.h"
#define closegr closegraph
void seedfilling(int x,int y,int fill_color,int boundary_color)
{
int c;
c=getpixel(x,y); /*获取当前点的颜色*/
if((c!=boundary_color)&&(c!=fill_color)) /*如果颜色为边界色则不填充*/
{
putpixel(x, y, fill_color); /*画点*/
getch(); /*加上这条语句可以显示填充状态 */
seedfilling(x-1,y, fill_color, boundary_color);
seedfilling(x,y-1, fill_color, boundary_color);
seedfilling(x+1, y, fill_color, boundary_color);
seedfilling(x, y+1, fill_color, boundary_color);
}
}
void main()
{
int a,b,color;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
int poly[10];
a=150 ;
b=140;
color=4;
poly[0] = 110; /* 第一个点的x坐标以及y坐标 */
poly[1] = 110;
poly[2] = 200; /* 第二点 */
poly[3] = 105;
poly[4] = 170; /* 第三点 */
poly[5] = 120;
poly[6]=150; /*第四点*/
poly[7]=170;
poly[8]=110; /*多边形的起点与终点一样*/
poly[9]=110;
drawpoly(5,poly);/* 显示各点连接起来的多边形 */
seedfilling(a,b,color,15); /*种子填充多边形*/
getch();
closegraph();
}
#include "graphics.h"
#define closegr closegraph
void seedfilling(int x,int y,int fill_color,int boundary_color)
{
int c;
c=getpixel(x,y); /*获取当前点的颜色*/
if((c!=boundary_color)&&(c!=fill_color)) /*如果颜色为边界色则不填充*/
{
putpixel(x, y, fill_color); /*画点*/
getch(); /*加上这条语句可以显示填充状态 */
seedfilling(x-1,y, fill_color, boundary_color);
seedfilling(x,y-1, fill_color, boundary_color);
seedfilling(x+1, y, fill_color, boundary_color);
seedfilling(x, y+1, fill_color, boundary_color);
}
}
void main()
{
int a,b,color;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
int poly[10];
a=150 ;
b=140;
color=4;
poly[0] = 110; /* 第一个点的x坐标以及y坐标 */
poly[1] = 110;
poly[2] = 200; /* 第二点 */
poly[3] = 105;
poly[4] = 170; /* 第三点 */
poly[5] = 120;
poly[6]=150; /*第四点*/
poly[7]=170;
poly[8]=110; /*多边形的起点与终点一样*/
poly[9]=110;
drawpoly(5,poly);/* 显示各点连接起来的多边形 */
seedfilling(a,b,color,15); /*种子填充多边形*/
getch();
closegraph();
}