akern-gkgoat-fork/sysdata/programs/render_example/src/examples/square.hb
2024-10-25 16:37:38 +01:00

31 lines
854 B
Plaintext

.{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(uint).((screen.width - side) / 2, (screen.height - side) / 2)
color := random.any(render.Color)
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.any(render.Color)
}
if pos.y == 0 | pos.y == screen.height - side {
vel.y = -vel.y
color = random.any(render.Color)
}
pos += @bitcast(vel)
}
return
}