line.c
963 Bytes
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "libfb.h"
/*---------------------------------------------------------------------
Make a line on the screen
---------------------------------------------------------------------*/
void
fbLine(int x0, int y0, int x1, int y1, u16 color)
{
int dx, dy, sx, sy, i, e;
int x = x0;
int y = y0;
if (x1-x0 > 0){
sx = 1;
dx = x1-x0;
} else if (x1-x0 < 0) {
sx = -1;
dx = x0-x1;
} else {
sx = 0;
dx = 0;
}
if (y1-y0 > 0){
sy = 1;
dy = y1-y0;
} else if (y1-y0 < 0) {
sy = -1;
dy = y0-y1;
} else {
sy = 0;
dy = 0;
}
if (dx >= dy) {
e = -dx;
for (i=0; i<= dx; i++){
fbPixel(x, y, color);
x += sx;
e += 2*dy;
if (e>=0) {
y += sy;
e -= 2*dx;
}
}
} else {
e = -dy;
for (i = 0; i <= dy; i ++){
fbPixel(x, y, color);
y += sy;
e += 2*dx;
if (e >= 0) {
x += sx;
e -= 2*dy;
}
}
}
}