line.c

来自「嵌入式系统中,从任意一点到任意一点画直线算法程序」· C语言 代码 · 共 48 行

C
48
字号
/********************************************************************************
* Organization  :                 							                                *
* Author        :                                                               *
* Module        :                                                               *
* Unit          :                                                               *
* Creation Date : 05/14/2007                                                    *
*********************************************************************************
*********************************************************************************
*                                                                               *
*                                                                               *
*                                                                               *
********************************************************************************/


/*=======================================================================================
*****************************************************************************************
Author: mcu - 05/14/2007
Design:
Globals:
	none
Paramet:
	none
=======================================================================================*/
#define   abs(a)     (a<0 ? -a : a)
#define   ROUND(a)   ((int)a+0.5)
//The   DDA   algorithm
void DrawLine(int xa, int ya, int xb, int yb,int nColor, int layer, int scaling)
{
  int   dx=xb-xa,   dy=yb-ya;
  int   steps,k;
  float   xincrement   ,yincrement,x=xa,y=ya;

  if(abs(dx)>abs(dy))
  steps=abs(dx);
  else
  steps=abs(dy);
  xincrement=dx/(float)steps;
  yincrement=dy/(float)steps;
	DrawPixel(ROUND(x), ROUND(y), nColor, layer,scaling);

  for(k=0;k<steps;k++)
  {
	  x+=xincrement;
	  y+=yincrement;
		DrawPixel(ROUND(x), ROUND(y), nColor, layer,scaling);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?