fix draw line
This commit is contained in:
@@ -33,17 +33,17 @@ draw_line :: (screen: *Screen, x1: s64, y1: s64, x2: s64, y2: s64, char: PIXEL_T
|
||||
draw(screen, x, y, char, color);
|
||||
|
||||
for 0..xe {
|
||||
x += 1;
|
||||
x = x + 1;
|
||||
|
||||
if px < 0 {
|
||||
px += 2 * dy1;
|
||||
px = px + 2 * dy1;
|
||||
} else {
|
||||
if (dx < 0 && dy < 0) || (dx > 0 && dy > 0) then y += 1; else y -= 1;
|
||||
px += 2 * (dy1 - dx1);
|
||||
if (dx < 0 && dy < 0) || (dx > 0 && dy > 0) then y = y + 1; else y = y - 1;
|
||||
px = px + 2 * (dy1 - dx1);
|
||||
}
|
||||
|
||||
draw(screen, x, y, char, color);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if dy >= 0 {
|
||||
x = x1;
|
||||
@@ -58,13 +58,13 @@ draw_line :: (screen: *Screen, x1: s64, y1: s64, x2: s64, y2: s64, char: PIXEL_T
|
||||
draw(screen, x, y, char, color);
|
||||
|
||||
for 0..ye {
|
||||
y += 1;
|
||||
y = y + 1;
|
||||
|
||||
if py <= 0 {
|
||||
py += 2 * dx1;
|
||||
py = py + 2 * dx1;
|
||||
} else {
|
||||
if (dx < 0 && dy < 0 ) || (dx > 0 && dy > 0) then x += 1; else x -= 1;
|
||||
py += 2 * (dx1 - dy1);
|
||||
if (dx < 0 && dy < 0 ) || (dx > 0 && dy > 0) then x = x + 1; else x = x - 1;
|
||||
py = py + 2 * (dx1 - dy1);
|
||||
}
|
||||
|
||||
draw(screen, x, y, char, color);
|
||||
|
||||
@@ -3,7 +3,8 @@ main :: () {
|
||||
screen := New(Screen);
|
||||
init_screen(screen, 5, 2);
|
||||
|
||||
draw_line(screen, 0, 0, 0, 0);
|
||||
draw_line(screen, 0, 0, 2, 0);
|
||||
draw(screen, 3, 0, color = .FG_GREEN);
|
||||
|
||||
print("%\n", screen.buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user