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

39 lines
1,012 B
Plaintext
Raw Normal View History

2024-10-14 19:24:29 -05:00
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
the lines example bounces around the screen */
example := fn(): void {
screen := render.init(true)
image := render.new_surface(341, 256)
p0 := Vec2(int).(0, 0)
p1 := Vec2(int).(0, image.height)
render.clear(image, .(100, 50, 0, 255))
loop if p0.y >= image.height break else {
render.put_line(image, p0, p1, .(255, 180, 100, 255))
render.put_line(image, .(image.width, image.height) - p0, .(image.width, image.height) - p1, .(255, 180, 100, 255))
p0.y += image.height >> 6
p1.x += image.width >> 6
}
vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100)
loop {
render.put_surface(screen, image, pos)
render.sync(screen)
render.clear(screen, render.black)
if pos.x == 0 | pos.x == screen.width - image.width {
vel.x = -vel.x
}
if pos.y == 0 | pos.y == screen.height - image.height {
vel.y = -vel.y
}
pos += vel
}
return
}