搜索
bottom↓
回复: 2

请大家看一下我这个在液晶中作直线的程序,我做了几个都没成功

[复制链接]

出0入0汤圆

发表于 2006-3-16 21:31:37 | 显示全部楼层 |阅读模式
我的是一个sed1335程序, 我已经作出一个没问题的作点程序

作直线程序可怎么也不怎么成功。应该是算法问题



例如,起点的x坐标、y坐标比终点小就能很好的画出



但是反过来就不可以了



/************************************************/

/*画线。任意方向的斜线,不支持垂直的或水平线 */

/************************************************/

     

void disp_Linexy(Uchar x_start,Uchar y_start,Uchar x_end,Uchar y_end,Uchar screen)

{

register Uchar t;

int xerr=0,yerr=0,delta_x,delta_y,distance;

Uchar incx,incy;



/*  compute the distance in both directions */

delta_x = x_end - x_start;

delta_y = y_end - y_start;



/* compute  the direction of the increment ,

an increment of "0" means either a vertical or horizontal lines */



if(delta_x>0) incx=1;

else if( delta_x==0 ) incx=0;

  else incx=-1;





if(delta_y>0) incy=1;

else if( delta_y==0 ) incy=0;

  else incy=-1;



/*  determine which distance is greater */

delta_x = cabs( delta_x );

delta_y = cabs( delta_y );



if( delta_x > delta_y ) distance=delta_x;

else distance=delta_y;



/* draw the line */

for( t=0;t <= distance+1; t++ ) {

    disp_Point(x_start,y_start,screen);

     xerr += delta_x ;

     yerr += delta_y ;

  if( xerr > distance ) {

   xerr-=distance;

       x_start+=incx;

  }

  if( yerr > distance ) {

   yerr-=distance;

       y_start+=incy;

  }

delay_ms(300);

}

}











/************************************************/

/*画线。任意方向的斜线,不支持垂直的或水平线 */

/************************************************/

void Linexy_new(Uint x1,Uchar y1,Uint xt,Uchar yt,Uchar screen)

{

    register Uchar t;

    int dx;

    char dy;

    Uint ix,iy,inc,plotx,x;

    Uchar ploty,y,plot,i;

    plotx=x1;

    ploty=y1;

    x=0;y=0;plot=1;

    dx=xt-x1;

    dy=yt-y1;

    ix=(dx>0)?dx:(-dx);

    iy=(dy>0)?dy:(-dy);

    inc=(ix>iy)?ix:iy;

    for(t=0;t<inc;t++)

    {

      if(plot)

       disp_Point(plotx,ploty,screen);

       x+=ix;

       y+=iy;

       plot=0;

       if(y>inc)

        {plot=1;

         y-=inc;

          if(dy>0)

            ploty++;

          if(dy<0)

            ploty--;

         }

       if(x>inc)

        {plot=1;

         x-=inc;

        if(dx>0)

          plotx++;

        if(dx<0)

          plotx--;

        }

   

}

   

}                          //画点



















/************************************************/

/*画线。任意方向的斜线,不支持垂直的或水平线 */

/************************************************/



void Linexy(Uchar x0,Uchar y0,Uchar xt,Uchar yt,Uchar screen)

{

    register Uchar t;

    int xerr=0,yerr=0,delta_x,delta_y,distance;

    int incx,incy;



    delta_x = xt-x0;                            //计算坐标增量

    delta_y = yt-y0;

   

    if(delta_x>0) incx=1;                       //设置单步方向

    else

    {

        if( delta_x==0  ) incx=0;               //垂直线

        else {incx=-1;delta_x=-delta_x;}

    }

    if(delta_y>0) incy=1;

    else

    {

        if( delta_y==0  ) incy=0;               //水平线

        else {incy=-1;delta_y=-delta_y;}

    }

    if( delta_x > delta_y ) distance=delta_x;   //选取基本增量坐标轴

    else distance=delta_y;



    for( t=0;t <= distance+1; t++ )

    {                                           //画线输出

        disp_Point(x0,y0,screen);                                //画点

        xerr += delta_x ;

        yerr += delta_y ;

        

        if( xerr >= distance )

        {

            xerr-=distance;

            x0+=incx;

        }

        if( yerr >= distance )

        {

            yerr-=distance;

           y0+=incy;

        }

    }

}
-----此内容被acr8于2006-03-16,21:32:48编辑过

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2006-3-17 11:22:22 | 显示全部楼层
我给你一个我写的画线的程序(与硬件无关),没有什么限制,但你要把你画点的程序做出来,该程序与硬件相关。如果你不需要清除,可去掉 bool clr 参数,当然你画点不要这个参数。



void line(uint8 x1, uint8 y1, uint8 x2, uint8 y2, bool clr)

{uint8 i, xsub, ysub;

bool dir;



    if(y1 > y2)

    {

        if(x2 > x1)

        {

            dir = true;

        }

        else

        {

            dir = false;

            i = x2;

            x2 = x1;

            x1 = i;

        }

        i = y2;

        y2 = y1;

        y1 = i;

    }

    else

    {

        dir = false;

        if(x1 > x2)

        {

            dir = true;

            i = x2;

            x2 = x1;

            x1 = i;

        }

    }



    xsub = x2 - x1 + 1;

    ysub = y2 - y1 + 1;

    x2 = x1;

    if(!dir)

    {

        y2 = y1;

    }

        

    for(y1 = 1; y1 <= ysub; y1++)

    {

        i = (uint16)(y1 * xsub) / ysub + x1;

        do

        {

            dot(x2, y2, clr);



            if(x2 < i)

            {

                ++x2;

            }

        }while(x2 < i);



        if(dir)

        {

            --y2;

        }

        else

        {

            ++y2;

        }

    }

}
-----此内容被yizheng于2006-03-17,11:33:28编辑过

出0入0汤圆

发表于 2012-10-22 13:28:20 | 显示全部楼层
我遇到了跟你同样的问题,请问你后来是怎么解决的?能不能指点一下我。。。我用的芯片是STM32F407VGT6 ,  想用它驱动LCD液晶屏 ,在液晶屏上画线 ,液晶屏驱动芯片是SSD1289  ,但是使用画线函数时,起点坐标比终点坐标小时可以正常画线,起点坐标比终点坐标大时,比如x0大于x1 或y0大于y1时,画出的直线就不对了
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 02:15

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表