.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math; .{random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb") /* expected result: a square that changes colour bounces around the screen */ 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))) loop { render.put_filled_rect(screen, pos, .(100, 100), color) render.sync(screen) render.clear(screen, render.black) if pos.x == 0 | pos.x == screen.width - 100 { vel.x = -vel.x color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) } if pos.y == 0 | pos.y == screen.height - 100 { vel.y = -vel.y color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) } pos += vel } return }