mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
75 lines
1.7 KiB
Plaintext
75 lines
1.7 KiB
Plaintext
import "env.memory" memory(4);
|
|
|
|
import "env.cls" fn cls(i32);
|
|
import "env.setPixel" fn setPixel(i32, i32, i32);
|
|
import "env.time" fn time() -> f32;
|
|
import "env.sin" fn sin(f32) -> f32;
|
|
import "env.cos" fn cos(f32) -> f32;
|
|
|
|
fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) {
|
|
let swapTmp: f32;
|
|
if x1 > x2 {
|
|
swapTmp = x1;
|
|
x1 = x2;
|
|
x2 = swapTmp;
|
|
swapTmp = y1;
|
|
y1 = y2;
|
|
y2 = swapTmp;
|
|
}
|
|
if x1 < 0.5 & x2 >= 0.5 {
|
|
y1 = y1 + (y2 - y1) * (0.5 - x1) / (x2 - x1);
|
|
x1 = 0.5;
|
|
}
|
|
if x1 < 319.5 & x2 >= 319.5 {
|
|
y2 = y2 + (y2 - y1) * (319.5 - x2) / (x2 - x1);
|
|
x2 = 319.5;
|
|
}
|
|
|
|
if y1 > y2 {
|
|
swapTmp = x1;
|
|
x1 = x2;
|
|
x2 = swapTmp;
|
|
swapTmp = y1;
|
|
y1 = y2;
|
|
y2 = swapTmp;
|
|
}
|
|
if y1 < 0.5 & y2 >= 0.5 {
|
|
x1 = x1 + (x2 - x1) * (0.5 - y1) / (y2 - y1);
|
|
y1 = 0.5;
|
|
}
|
|
if y1 < 239.5 & y2 >= 239.5 {
|
|
x2 = x2 + (x2 - x1) * (239.5 - y2) / (y2 - y1);
|
|
y2 = 239.5;
|
|
}
|
|
|
|
let dx = x2 - x1;
|
|
let dy = y2 - y1;
|
|
let steps: i32;
|
|
if abs(dx) >= dy {
|
|
dy = dy / abs(dx);
|
|
steps = abs(dx) as i32;
|
|
dx = select(dx > 0 as f32, 1 as f32, -1 as f32);
|
|
} else {
|
|
dx = dx / dy;
|
|
steps = dy as i32;
|
|
dy = 1 as f32;
|
|
}
|
|
|
|
loop pixels {
|
|
setPixel(x1 as i32, y1 as i32, col);
|
|
x1 = x1 + dx;
|
|
y1 = y1 + dy;
|
|
branch_if (steps := steps - 1) >= 0: pixels;
|
|
}
|
|
}
|
|
|
|
export fn upd() {
|
|
cls(0);
|
|
let i: i32;
|
|
loop lines {
|
|
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);
|
|
branch_if (i := i + 1) < 50: lines;
|
|
}
|
|
}
|