码迷,mamicode.com
首页 > 编程语言 > 详细

DDA画线算法

时间:2017-05-08 09:55:23      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:std   for   line   sys   math.h   put   logs   art   img   

#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 = 0; k < espl;k++)

    {

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

        x += xIncre;

        y += yIncre;

    }

}

技术分享技术分享技术分享技术分享

DDA画线算法

标签:std   for   line   sys   math.h   put   logs   art   img   

原文地址:http://www.cnblogs.com/cdp1591652208/p/6823057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!