From 34cbd9a5e6c945373dc9c9599e16ddfbe9bd2c8a Mon Sep 17 00:00:00 2001 From: koniifer Date: Tue, 15 Oct 2024 21:43:23 +0100 Subject: [PATCH] fiddling --- sysdata/libraries/stn/src/random.hb | 3 ++- .../src/examples/{ => assets}/able.bmp | Bin .../src/examples/{ => assets}/mini.bmp | Bin .../render_example/src/examples/image.hb | 4 ++-- .../render_example/src/examples/square.hb | 15 ++++++++------- .../render_example/src/examples/surface.hb | 17 +++++++++-------- sysdata/programs/render_example/src/main.hb | 5 +---- 7 files changed, 22 insertions(+), 22 deletions(-) rename sysdata/programs/render_example/src/examples/{ => assets}/able.bmp (100%) rename sysdata/programs/render_example/src/examples/{ => assets}/mini.bmp (100%) diff --git a/sysdata/libraries/stn/src/random.hb b/sysdata/libraries/stn/src/random.hb index 1e625602..9b4cdfc6 100644 --- a/sysdata/libraries/stn/src/random.hb +++ b/sysdata/libraries/stn/src/random.hb @@ -3,5 +3,6 @@ any := fn($Expr: type): Expr { } range := fn($Expr: type, min: Expr, max: Expr): Expr { - return @eca(3, 4) % (max - min + 1) + min + // wtf is this + return @intcast(@as(int, @eca(3, 4)) % @as(int, @intcast(max) - @intcast(min)) + 1 + @intcast(min)) } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/able.bmp b/sysdata/programs/render_example/src/examples/assets/able.bmp similarity index 100% rename from sysdata/programs/render_example/src/examples/able.bmp rename to sysdata/programs/render_example/src/examples/assets/able.bmp diff --git a/sysdata/programs/render_example/src/examples/mini.bmp b/sysdata/programs/render_example/src/examples/assets/mini.bmp similarity index 100% rename from sysdata/programs/render_example/src/examples/mini.bmp rename to sysdata/programs/render_example/src/examples/assets/mini.bmp diff --git a/sysdata/programs/render_example/src/examples/image.hb b/sysdata/programs/render_example/src/examples/image.hb index b1ac1dee..ce59daf4 100644 --- a/sysdata/programs/render_example/src/examples/image.hb +++ b/sysdata/programs/render_example/src/examples/image.hb @@ -4,8 +4,8 @@ render := @use("../../../../libraries/render/src/lib.hb") /* expected result: a cute image bounces around the screen */ -bmp_1 := @embed("./able.bmp") -bmp_2 := @embed("./mini.bmp") +bmp_1 := @embed("./assets/able.bmp") +bmp_2 := @embed("./assets/mini.bmp") example := fn(): void { screen := render.init(true) diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 09f71e09..5f894956 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -8,20 +8,21 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { screen := render.init(true) vel := Vec2(int).(1, 1) - pos := Vec2(int).(100, 100) - color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + side := screen.width / 8 + pos := Vec2(int).((screen.width - side) / 2, (screen.height - side) / 2) + color := random.range(render.Color, render.black, render.white) loop { - render.put_filled_rect(screen, pos, .(100, 100), color) + render.put_filled_rect(screen, pos, .(side, side), color) render.sync(screen) render.clear(screen, render.black) - if pos.x == 0 | pos.x == screen.width - 100 { + if pos.x == 0 | pos.x == screen.width - side { vel.x = -vel.x - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.range(render.Color, render.black, render.white) } - if pos.y == 0 | pos.y == screen.height - 100 { + if pos.y == 0 | pos.y == screen.height - side { vel.y = -vel.y - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.range(render.Color, render.black, render.white) } pos += vel diff --git a/sysdata/programs/render_example/src/examples/surface.hb b/sysdata/programs/render_example/src/examples/surface.hb index 7eec6d43..191c8ad8 100644 --- a/sysdata/programs/render_example/src/examples/surface.hb +++ b/sysdata/programs/render_example/src/examples/surface.hb @@ -8,29 +8,30 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { screen := render.init(true) - image := render.new_surface(341, 256) + image := render.new_surface(screen.width / 3, screen.height / 3) vel := Vec2(int).(-1, -1) pos := Vec2(int).(100, 100) + side := image.width / 8 vel_inner := Vec2(int).(1, 1) - pos_inner := Vec2(int).(10, 10) - color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2) + color := random.range(render.Color, render.black, render.white) loop { render.clear(image, render.black) render.clear(screen, render.black) - render.put_filled_rect(image, pos_inner, .(100, 100), color) + render.put_filled_rect(image, pos_inner, .(side, side), color) render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), render.white) render.put_surface(screen, image, pos) render.sync(screen) - if pos_inner.x == 0 | pos_inner.x == image.width - 100 { + if pos_inner.x == 0 | pos_inner.x == image.width - side { vel_inner.x = -vel_inner.x - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.range(render.Color, render.black, render.white) } - if pos_inner.y == 0 | pos_inner.y == image.height - 100 { + if pos_inner.y == 0 | pos_inner.y == image.height - side { vel_inner.y = -vel_inner.y - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.range(render.Color, render.black, render.white) } if pos.x == 0 | pos.x == screen.width - image.width { diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index a3981b65..289d8128 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,6 +1,3 @@ .{example} := @use("./examples/surface.hb") -main := fn(): void { - @inline(example) - return -} \ No newline at end of file +main := example \ No newline at end of file