void drawline int _x _y fl int dx _abs _x2 dy _abs _y2 int sy sx if dx

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void drawline(){
int x = _x, y = _y,fl=0;
int dx = _abs(_x2 - x), dy=_abs(_y2 - y);
int sy , sx;
if (dx){
sx = (_x2 - x) / dx;
} else {
sx = 0;
}
if (dy){
sy = (_y2 - y) / dy;
} else {
sy = 0;
}
if (dy > dx){
int t = dx;
dx = dy;
dy = t;
fl = 1;
}
int e = - dx,de=2*dy;
for (int i = 0; i < dx; i++){
SetPixel(x, y);
e += de;
if (fl){
y += sy;
} else {
x += sx;
}
while (e >= 0){
if (fl){
x += sx;
}
else {
y += sy;
}
e -= 2 * dx;
}
}
}