1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/programs/render_example/src/examples/square.hb
2024-10-15 21:43:23 +01:00

31 lines
933 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(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
}