#include<stdio.h>

 #include"graphics.h"

 #include<math.h>

 #include<stdlib.h>

 void DDALine(int x0, int y0, int x1, int y1);

 int main()

 {

     int gdriver = DETECT, gmode;

     int x0, y0, x1, y1;

     printf("please input the start point:\n");

     scanf_s("%d%d", &x0, &y0);

     printf("please input the end point:\n");

     scanf_s("%d%d", &x1, &y1);

     initgraph(&gdriver, &gmode, "");    //初始化图形界面

     DDALine(x0, y0, x1, y1);

     system("pause");    //暂停函数

     closegraph();   //关闭图形界面

 }

 void DDALine(int x0, int y0, int x1, int y1)

 {

     int dx=x1-x0, dy=y1-y0,k;

     double x = x0, y = y0, xIncre, yIncre, espl;

     espl = abs(dy);

     if (abs(dx) > abs(dy))

         espl = abs(dx);

     xIncre = 1.0*dx / espl;

     yIncre = 1.0*dy / espl;

     for (k = ; k < espl;k++)

     {

         putpixel((int)x, (int)y, RED);

         x += xIncre;

         y += yIncre;

     }

 }

DDA画线算法-LMLPHPDDA画线算法-LMLPHPDDA画线算法-LMLPHPDDA画线算法-LMLPHP

05-11 20:26