种子填充其实很简单,计算机图形学中介绍的使用栈,感觉作者是不是脑子进水了,直接使用一个队列用广搜就可以了啊,但是我就懒得写了,直接一个递归算了,有兴趣的同学自己试一试
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
int Graph[500][500] ;
void scanline_seed_fill(int color,int sx,int sy)
{
Graph[sx][sy] = 1 ;
putpixel(sx, sy, color);
if(Graph[sx+1][sy] == 0 && sx+1 < 500)
{
Sleep(50);
scanline_seed_fill(color,sx + 1,sy);
}
if(Graph[sx-1][sy] == 0 &&sx - 1 > 0)
{
Sleep(50);
scanline_seed_fill(color,sx - 1,sy);
}
if(Graph[sx][sy+1] == 0 && sy+1 < 500)
{
Sleep(50);
scanline_seed_fill(color,sx ,sy + 1);
}
if(Graph[sx][sy-1] == 0 && sy - 1 > 0)
{
Sleep(50);
scanline_seed_fill(color,sx,sy - 1);
}
}
void Seed_fill(int startX,int startY,int color){
int driver=VGA,mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(0);
int x;
int y;
//画图形
for(x=1,y=50;x<=50 && y>=1;x++,y--)
{
putpixel(x,y,color);
Graph[x][y]=1;
}
for(x=100,y=1;x<=150 && y<=50;x++,y++)
{
putpixel(x,y,color);
Graph[x][y]=1;
}
for(x=1,y=100;x<=50 && y<=150;x++,y++)
{
putpixel(x,y,color);
Graph[x][y]=1;
}
for(x=100,y=150;x<=150 && y>=100;x++,y--)
{
putpixel(x,y,color);
Graph[x][y]=1;
}
for(x=50;x<=100;x++)
{
putpixel(x,1,color);
Graph[x][1]=1;
putpixel(x,150,color);
Graph[x][150]=1;
}
for(y=50;y<=100;y++)
{
putpixel(1,y,color);
Graph[1][y]=1;
putpixel(150,y,color);
Graph[150][y]=1;
}
getchar();
scanline_seed_fill(255,startX,startY);
getch();
}
int main()
{
initgraph(1000,1000); //初始化图
Seed_fill(100,100,255);
getchar(); //暂停画面
return 0;
}