帮忙看个程序呗!是用C语言写的区域填充问题!

wangzi041 2007-04-08 10:26:22
#include "stdio.h"
#include "graphics.h"
#define MAX 600
#define FALSE 0
#define TRUE 1
typedef struct
{
int x;
int y;
}elemtype;
typedef struct
{
elemtype data[MAX] ;
int top;
int size;
}sta ;
void init(sta *stack)
{stack->top=0;
stack->size=0;
}

int isstackempty(sta *stack) /*判断栈是否为空*/
{
if (stack->size==0)
return 1;
else
return 0;


}
void stackpush(sta *stack,elemtype point) /*压栈*/
{
stack->top++;
stack->data[stack->top]=point;
}
elemtype stackpop(sta *stack) /*出栈,并且返回值*/
{
return stack->data[stack->top--];

}

void scanlinefill(int x,int y,int oldcolor,int newcolor)
{
int xl,xr;
int spanneedfill;
elemtype pt;
sta stack;
init(&stack);
pt.x=x;
pt.y=y;
stackpush(&stack,pt);
while(!isstackempty(&stack))
{
pt=stackpop(&stack);
y=pt.y;
x=pt.x;
while(getpixel(x,y)==oldcolor)
{
putpixel(x,y,newcolor);
x++;
}
xr=x-1;
x=pt.x-1;
while(getpixel(x,y)==oldcolor)
{
putpixel(x,y,newcolor);
x--;
}
xl=x+1;
x=xl;
y+=1;
while(x<xr)
{
spanneedfill=FALSE;
while(getpixel(x,y)==oldcolor)
{
spanneedfill=TRUE;
x++;
}
if(spanneedfill)
{
pt.x=x-1;
pt.y=y;
stackpush(&stack,pt);
spanneedfill=FALSE;
}
while(getpixel(x,y)!=oldcolor&&x<xr)x++;
}
x=xl;
y=y-2;
while(x<xr)
{
spanneedfill=FALSE;
while(getpixel(x,y)==oldcolor)
{
spanneedfill=TRUE;
x++;

}
if(spanneedfill)
{
pt.x=x-1;
pt.y=y;
stackpush(&stack,pt);
spanneedfill=FALSE;
}
while(getpixel(x,y)!=oldcolor&&x<xr)x++;
}
}

}
main()
{
int gdriver=DETECT,gmode;
int i;
int newcolor,oldcolor;
initgraph(&gdriver,&gmode,"");
setbkcolor(BLACK);
bar(0,0,100,100);
newcolor=getpixel(150,150);
oldcolor=getpixel(10,10);
scanlinefill(50,50,oldcolor,newcolor);
getch();
closegraph();
}


不知道错在哪里了!
就是出不了结果!
...全文
329 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
al0n9 2007-04-09
  • 打赏
  • 举报
回复
bar(0,0,100,100);
是用当前颜色画一个bar,当前颜色你没有设置,默认应该为黑色吧?
wangzi041 2007-04-09
  • 打赏
  • 举报
回复
不是啊!
bar(0,0,100,100);
画了一个白色的正方形;
既然填充的话那就应该全部变成黑色吧!
wangzi041 2007-04-09
  • 打赏
  • 举报
回复
默认的是黑色的!

我试了!
没有什么用啊~~
帮忙看看
al0n9 2007-04-08
  • 打赏
  • 举报
回复
setbkcolor(BLACK);

只设置了背景色,没有前景色。在黑色背景上画黑色图形,能出来什么内容?

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧