.{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) 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, .(side, side), color) render.sync(screen) render.clear(screen, render.black) if pos.x == 0 | pos.x == screen.width - side { vel.x = -vel.x color = random.range(render.Color, render.black, render.white) } if pos.y == 0 | pos.y == screen.height - side { vel.y = -vel.y color = random.range(render.Color, render.black, render.white) } pos += vel } return }