#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);
}
}