1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/programs/render_example/src/examples/square.hb

32 lines
875 B
Plaintext
Raw Normal View History

2024-10-12 15:39:09 -05:00
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
.{random} := @use("../../../../libraries/stn/src/lib.hb")
2024-09-13 16:41:31 -05:00
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
a square that changes colour bounces around the screen */
2024-09-13 16:41:31 -05:00
example := fn(): void {
render.init()
2024-10-12 15:39:09 -05:00
vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100)
2024-09-13 16:41:31 -05:00
width := render.width()
height := render.height()
2024-10-12 15:39:09 -05:00
color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
2024-09-13 16:41:31 -05:00
loop {
render.put_filled_rect(pos, .(100, 100), color)
2024-09-13 16:41:31 -05:00
render.sync()
render.clear(render.black)
if pos.x == 0 | pos.x == width - 100 {
vel.x = -vel.x
2024-10-12 15:39:09 -05:00
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
2024-09-13 16:41:31 -05:00
}
if pos.y == 0 | pos.y == height - 100 {
vel.y = -vel.y
2024-10-12 15:39:09 -05:00
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
2024-09-13 16:41:31 -05:00
}
pos += vel
}
return
}