MidpointLine

来源:互联网 发布:移动网络解锁 编辑:程序博客网 时间:2024/06/05 15:19
#include < graphics.h > #include < math.h > void MidpointLine(int x0, int y0, int x1, int y1);int main(void) {    int gdriver = DETECT,    gmode,    errorcode;    int bkcolor,    midx,    midy;    initgraph( & gdriver, &gmode, "");    setcolor(RED);    MidpointLine(0, 0, 639, 479);    getch();    closegraph();    return 0;}void MidpointLine(int x0, int y0, int x1, int y1) {    int color;    int a,    b,    delta1,    delta2,    d,    x,    y;    a = y0 - y1;    b = x1 - x0;    d = a + a + b;    delta1 = a + a;    delta2 = a + a + b + b;    x = x0;    y = y0;    color = getcolor();    putpixel(x, y, color);    while (x < x1) {        if (d < 0) {            x++;            y++;            d += delta2;        } else {            x++;            d += delta1;        }        putpixel(x, y, color);    }}

0 0
原创粉丝点击