首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2012-02-27 
帮忙看个程序呗!是用C语言写的区域填充问题!#includestdio.h #includegraphics.h #defineMAX600#defin

帮忙看个程序呗!是用C语言写的区域填充问题!
#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();
}


不知道错在哪里了!
就是出不了结果!

[解决办法]
setbkcolor(BLACK);

只设置了背景色,没有前景色。在黑色背景上画黑色图形,能出来什么内容?
[解决办法]
bar(0,0,100,100);
是用当前颜色画一个bar,当前颜色你没有设置,默认应该为黑色吧?

热点排行