diff --git a/examples/curlywas/line.cwa b/examples/curlywas/line.cwa new file mode 100644 index 0000000..27f4bfa --- /dev/null +++ b/examples/curlywas/line.cwa @@ -0,0 +1,74 @@ +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; + } +} diff --git a/platform/src/font.png b/platform/src/font.png index 783a691..06c2f99 100644 Binary files a/platform/src/font.png and b/platform/src/font.png differ diff --git a/platform/src/font.pxo b/platform/src/font.pxo index 5fe7f8a..47b9bf2 100644 Binary files a/platform/src/font.pxo and b/platform/src/font.pxo differ