fix line drawing

This commit is contained in:
2021-12-11 23:27:38 +01:00
parent 88182f94ee
commit 72e977c4ba

View File

@@ -35,15 +35,15 @@ fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
} }
if y1 < 0 as f32 & y2 >= 0 as f32 { if y1 < 0 as f32 & y2 >= 0 as f32 {
x1 = x1 + (x2 - x1) * -y1 / (y2 - y1); x1 = x1 + (x2 - x1) * -y1 / (y2 - y1);
y1 = 0.0; y1 = 0 as f32;
} }
if y1 < 240 as f32 & y2 >= 240 as f32 { if y1 < 240 as f32 & y2 >= 240 as f32 {
x2 = x2 + (x2 - x1) * (240 as f32 - y2) / (y2 - y1); x2 = x2 + (x2 - x1) * (240 as f32 - y2) / (y2 - y1);
y2 = 240 as f32; y2 = 240 as f32;
} }
let dx = x2 - x1; let lazy dx = x2 - x1;
let dy = y2 - y1; let lazy dy = y2 - y1;
let max_axis: f32; let max_axis: f32;
let p: f32; let p: f32;
if abs(dx) >= dy { if abs(dx) >= dy {
@@ -58,7 +58,7 @@ fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
p = floor(p) + 0.5 - p; p = floor(p) + 0.5 - p;
if max_axis < 0 as f32 { if max_axis < 0 as f32 {
steps = -steps; steps = -steps;
p = 1 as f32 - p; p = -p;
max_axis = -max_axis; max_axis = -max_axis;
} }
dx = dx / max_axis; dx = dx / max_axis;
@@ -91,12 +91,12 @@ fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
export fn upd() { export fn upd() {
cls(0); cls(0);
//line(0.0, 4.0, 7.0, -2.0, 15); // line(0.0, 4.0, 7.0, -2.0, 15);
//return; // return;
let i: i32; let i: i32;
loop lines { loop lines {
let angle = i as f32 * (3.1415 / 25.0) + time() * 0.01; let angle = i as f32 * (3.1415 / 25.0) + time() * 0.1;
line(160.0, 120.0, 160.0 + sin(angle) * 200.0, 120.0 + cos(angle) * 200.0, 47); line(160.0, 120.0, 160.0 + sin(angle) * 100.0, 120.0 + cos(angle) * 100.0, 47);
branch_if (i := i + 1) < 50: lines; branch_if (i := i + 1) < 50: lines;
} }
} }