1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
peony 2024-10-16 00:39:27 +02:00
commit 1039db1247
24 changed files with 324 additions and 315 deletions

10
Cargo.lock generated
View file

@ -350,12 +350,12 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
dependencies = [
"hashbrown 0.15.0",
"hbbytecode",
@ -367,7 +367,7 @@ dependencies = [
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c9b85f9004b7a5d4a4cad68bdf4eb2c1e75d811e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ea736d88244ce1d85999d7ce6387a63c655b7000"
dependencies = [
"hbbytecode",
]
@ -985,9 +985,9 @@ dependencies = [
[[package]]
name = "rustversion"
version = "1.0.17"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
[[package]]
name = "ryu"

View file

@ -3,7 +3,7 @@ pub static SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole {
uart: 0x09000000 as *mut u8,
});
struct SerialConsole {
pub struct SerialConsole {
uart: *mut u8,
}

View file

@ -1,11 +1,5 @@
.{Color} := @use("./lib.hb");
.{memory, log} := @use("../../stn/src/lib.hb")
Image := struct {
buf: ^Color,
width: i32,
height: i32,
}
.{Color, Surface} := @use("./lib.hb");
.{log} := @use("../../stn/src/lib.hb")
BitmapFileHeader := packed struct {
img_type: u16,
@ -38,14 +32,35 @@ BitmapColorHeader := packed struct {
unused: u32,
}
from_bmp := fn(bmp: ^u8): Image {
surface_from_bmp := fn(bmp: ^u8): Surface {
file_header := @as(^BitmapFileHeader, @bitcast(bmp))
if file_header.img_type != 0x4D42 {
log.error("failed to load bmp image: not a bmp image, idiot\0")
return @as(Image, idk)
return @as(Surface, idk)
}
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
bmp += file_header.offset
return .(@bitcast(bmp), @bitcast(info_header.width), @bitcast(info_header.height))
a := 0
px := info_header.width * info_header.height
ptr := @as(^Color, @bitcast(bmp))
tmp := @as(Color, idk)
row := 0
loop if row == info_header.height / 2 break else {
col := 0
loop if col == info_header.width break else {
top_index := row * info_header.width + col
bottom_index := (info_header.height - 1 - row) * info_header.width + col
tmp = *(ptr + top_index);
*(ptr + top_index) = *(ptr + bottom_index);
*(ptr + bottom_index) = tmp
col += 1
}
row += 1
}
return .(@bitcast(bmp), @intcast(info_header.width), @intcast(info_header.height))
}

View file

@ -1,4 +1,4 @@
svga := @use("svga.hb")
.{memory} := @use("../../stn/src/lib.hb")
software := @use("software.hb")
image := @use("image.hb")
@ -8,9 +8,36 @@ mode := software
init := mode.init
doublebuffer := mode.doublebuffer
Surface := struct {
buf: ^Color,
width: int,
height: int,
}
new_surface := fn(width: int, height: int): Surface {
return .(
@inline(memory.alloc, Color, width * height * @bitcast(@sizeof(Color))),
width,
height,
)
}
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): Surface {
return .(
ptr,
width,
height,
)
}
clone_surface := fn(surface: Surface): Surface {
new := new_surface(surface.width, surface.height)
@inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height))
return new
}
// Colours
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
Image := image.Image
white := Color.(255, 255, 255, 255)
black := Color.(0, 0, 0, 255)
gray := Color.(127, 127, 127, 255)
@ -34,17 +61,17 @@ put_rect := mode.put_rect
put_filled_rect := mode.put_filled_rect
put_line := mode.put_line
clear := mode.clear
put_image := mode.put_image
put_surface := mode.put_surface
// thanks peony for these three!
put_trirect := mode.put_trirect
put_vline := mode.put_vline
put_hline := mode.put_hline
// Display
width := mode.width
height := mode.height
dimensions := mode.dimensions
set_height := mode.set_height
set_width := mode.set_width
set_dimensions := mode.set_dimensions
// width := mode.width
// height := mode.height
// dimensions := mode.dimensions
// set_height := mode.set_height
// set_width := mode.set_width
// set_dimensions := mode.set_dimensions
sync := mode.sync

View file

@ -1,102 +1,77 @@
.{math, memory, dt} := @use("../../stn/src/lib.hb");
.{Color, Image} := @use("lib.hb");
.{Color, Surface, new_surface} := @use("lib.hb");
.{Vec2} := math
ctx := @as(Context, idk)
framebuffer := @as(^Color, idk)
Context := struct {
fb: ^Color,
bb: ^Color,
buf: ^Color,
width: int,
height: int,
pixels: int,
double_buffer: bool,
}
init := fn(): void {
init := fn(double_buffer: bool): Surface {
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
width := dt.get(int, "framebuffer/fb0/width\0")
height := dt.get(int, "framebuffer/fb0/height\0")
pixels := width * height
back_buffer := memory.alloc(Color, pixels * @bitcast(@sizeof(Color)))
ctx = Context.{
fb: dt.get(^Color, "framebuffer/fb0/ptr\0"),
bb: back_buffer,
buf: back_buffer,
width,
height,
pixels,
double_buffer: true,
}
return
}
doublebuffer := fn(enable: bool): void {
if enable {
ctx.buf = ctx.bb
if double_buffer {
return new_surface(width, height)
} else {
ctx.buf = ctx.fb
return .(framebuffer, width, height)
}
ctx.double_buffer = enable
}
clear := fn(surface: Surface, color: Color): void {
return @inline(memory.set, Color, &color, surface.buf, @bitcast(surface.width * surface.height))
}
sync := fn(surface: Surface): void {
return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height))
}
screenidx := fn(surface: Surface, x: int, y: int): int {
return x + surface.width * y
}
put_pixel := fn(surface: Surface, pos: Vec2(int), color: Color): void {
*(surface.buf + @inline(screenidx, surface, pos.x, pos.y)) = color
return
}
clear := fn(color: Color): void {
return @inline(memory.set, Color, &color, ctx.buf, @bitcast(ctx.pixels))
put_filled_rect := fn(surface: Surface, pos: Vec2(int), tr: Vec2(int), color: Color): void {
top_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y)
bottom_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y + tr.y - 1)
rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else {
@inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x))
@inline(memory.set, Color, &color, bottom_start_idx, @bitcast(tr.x))
top_start_idx += surface.width
bottom_start_idx -= surface.width
rows_to_fill -= 2
}
sync := fn(): void {
return @inline(memory.copy, Color, ctx.buf, ctx.fb, @bitcast(ctx.pixels))
}
width := fn(): int {
return ctx.width
}
height := fn(): int {
return ctx.height
}
screenidx := fn(x: int, y: int): int {
return x + ctx.width * y
}
put_pixel := fn(pos: Vec2(int), color: Color): void {
*(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color
return
}
put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
start_idx := @inline(screenidx, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + tr.y)
loop if start_idx >= end_idx break else {
@inline(memory.set, Color, &color, ctx.buf + start_idx, @bitcast(tr.x))
start_idx += ctx.width
if rows_to_fill == 1 {
@inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x))
}
return
}
put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
start_idx := @inline(screenidx, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + tr.y)
right_start_idx := @inline(screenidx, pos.x + tr.x, pos.y)
put_rect := fn(surface: Surface, pos: Vec2(int), tr: Vec2(int), color: Color): void {
start_idx := @inline(screenidx, surface, pos.x, pos.y)
end_idx := @inline(screenidx, surface, pos.x, pos.y + tr.y)
right_start_idx := @inline(screenidx, surface, pos.x + tr.x, pos.y)
loop if start_idx > end_idx break else {
*(ctx.buf + start_idx) = color;
*(ctx.buf + right_start_idx) = color
start_idx += ctx.width
right_start_idx += ctx.width
*(surface.buf + start_idx) = color;
*(surface.buf + right_start_idx) = color
start_idx += surface.width
right_start_idx += surface.width
}
@inline(memory.set, Color, &color, ctx.buf + @inline(screenidx, pos.x, pos.y), @bitcast(tr.x + 1))
@inline(memory.set, Color, &color, ctx.buf + @inline(screenidx, pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
@inline(memory.set, Color, &color, surface.buf + @inline(screenidx, surface, pos.x, pos.y), @bitcast(tr.x + 1))
@inline(memory.set, Color, &color, surface.buf + @inline(screenidx, surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
return
}
put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
put_line_low := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x
dy := p1.y - p0.y
yi := 1
@ -108,7 +83,7 @@ put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
y := p0.y
x := p0.x
loop if x == p1.x break else {
*(ctx.buf + @inline(screenidx, x, y)) = color
*(surface.buf + @inline(screenidx, surface, x, y)) = color
if D > 0 {
y += yi
D += 2 * (dy - dx)
@ -120,7 +95,7 @@ put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
put_line_high := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x
dy := p1.y - p0.y
xi := 1
@ -132,7 +107,7 @@ put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
x := p0.x
y := p0.y
loop if y == p1.y break else {
*(ctx.buf + @inline(screenidx, x, y)) = color
*(surface.buf + @inline(screenidx, surface, x, y)) = color
if D > 0 {
x += xi
D += 2 * (dx - dy)
@ -144,61 +119,50 @@ put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
put_line := fn(surface: Surface, p0: Vec2(int), p1: Vec2(int), color: Color): void {
if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) {
if p0.x > p1.x {
@inline(put_line_low, p1, p0, color)
@inline(put_line_low, surface, p1, p0, color)
} else {
@inline(put_line_low, p0, p1, color)
@inline(put_line_low, surface, p0, p1, color)
}
} else {
if p0.y > p1.y {
@inline(put_line_high, p1, p0, color)
@inline(put_line_high, surface, p1, p0, color)
} else {
@inline(put_line_high, p0, p1, color)
@inline(put_line_high, surface, p0, p1, color)
}
}
return
}
set_height := fn(new: int): void {
return
put_surface := fn(surface: Surface, top: Surface, pos: Vec2(int)): void {
top_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y)
bottom_start_idx := surface.buf + @inline(screenidx, surface, pos.x, pos.y + top.height - 1)
rows_to_copy := top.height
top_cursor := top.buf
bottom_cursor := top.buf + top.width * (top.height - 1)
loop if rows_to_copy <= 1 break else {
@inline(memory.copy, Color, top_cursor, top_start_idx, @bitcast(top.width))
@inline(memory.copy, Color, bottom_cursor, bottom_start_idx, @bitcast(top.width))
top_start_idx += surface.width
bottom_start_idx -= surface.width
top_cursor += top.width
bottom_cursor -= top.width
rows_to_copy -= 2
}
set_width := fn(new: int): void {
return
if rows_to_copy == 1 {
@inline(memory.copy, Color, top_cursor, top_start_idx, @bitcast(top.width))
}
dimensions := fn(): Vec2(int) {
return .(ctx.width, ctx.height)
}
set_dimensions := fn(new: Vec2(int)): void {
return
}
put_image := fn(image: Image, pos: Vec2(int)): void {
// y := 0
// loop if y == image.height break else {
// @inline(memory.copy, Color, image.buf + y * image.width, ctx.buf + @inline(screenidx, pos.x, pos.y + image.height - y), @intcast(image.width))
// y += 1
// }
// return
start_idx := @inline(screenidx, pos.x, pos.y)
end_idx := @inline(screenidx, pos.x, pos.y + image.height)
cursor := image.width * image.height
loop if start_idx >= end_idx break else {
@inline(memory.copy, Color, image.buf + cursor, ctx.buf + start_idx, @intcast(image.width))
start_idx += ctx.width
cursor -= image.width
}
return
}
// peony-made
put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void {
put_trirect := fn(surface: Surface, pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void {
step := Vec2(int).(1, 1)
if size.x < 0 {
step.x = -1
@ -211,8 +175,8 @@ put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color)
target := pos + size
loop if pos.x == target.x break else {
put_vline(pos.x, pos.y, target.y, color0)
@inline(put_vline, pos.x, pos.y, start_y, color1)
put_vline(surface, pos.x, pos.y, target.y, color0)
@inline(put_vline, surface, pos.x, pos.y, start_y, color1)
pos += step
}
@ -220,7 +184,7 @@ put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color)
}
// peony-made
put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
put_vline := fn(surface: Surface, x: int, y0: int, y1: int, color: Color): void {
if y1 < y0 {
tmp := y0
y0 = y1
@ -229,7 +193,7 @@ put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
y := y0
loop if y == y1 break else {
*(ctx.buf + @inline(screenidx, x, y)) = color
*(surface.buf + @inline(screenidx, surface, x, y)) = color
y += 1
}
@ -237,7 +201,7 @@ put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
}
// peony-made
put_hline := fn(y: int, x0: int, x1: int, color: Color): void {
put_hline := fn(surface: Surface, y: int, x0: int, x1: int, color: Color): void {
if x1 < x0 {
tmp := x0
x0 = x1
@ -246,7 +210,7 @@ put_hline := fn(y: int, x0: int, x1: int, color: Color): void {
x := x0
loop if x == x1 break else {
*(ctx.buf + @inline(screenidx, x, y)) = color
*(surface.buf + @inline(screenidx, surface, x, y)) = color
x += 1
}

View file

@ -1,78 +0,0 @@
.{Vec2} := @use("../../stn/src/lib.hb").math;
.{Image, Color} := @use("lib.hb")
clear := fn(color: Color): void {
return
}
width := fn(): int {
return 0
}
height := fn(): int {
return 0
}
dimensions := fn(): Vec2(int) {
return .(0, 0)
}
put_pixel := fn(position: Vec2(int), color: Color): void {
return
}
put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return
}
put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return
}
put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
// do not use, use line() instead
put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return
}
set_height := fn(new: int): void {
return
}
set_width := fn(new: int): void {
return
}
set_dimensions := fn(new: Vec2(int)): void {
return
}
sync := fn(): void {
return
}
init := fn(): void {
return
}
put_image := fn(img: Image, pos: Vec2(int)): void {
return
}
put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void {
return
}
put_vline := fn(x: int, y0: int, y1: int, color: Color): void {
return
}
put_hline := fn(y: int, x0: int, x1: int, color: Color): void {
return
}

View file

@ -2,7 +2,7 @@ PAGE_SIZE := 4096
MAX_ALLOC := 0xFF
alloc := fn($Expr: type, bytes: int): ^Expr {
pages := (1 + bytes) / PAGE_SIZE
pages := 1 + bytes / PAGE_SIZE
if pages <= MAX_ALLOC {
return @bitcast(@inline(request_page, pages))
}

View file

@ -3,5 +3,6 @@ any := fn($Expr: type): Expr {
}
range := fn($Expr: type, min: Expr, max: Expr): Expr {
return @eca(3, 4) % (max - min + 1) + min
// wtf is this
return @intcast(@as(int, @eca(3, 4)) % @as(int, @intcast(max) - @intcast(min)) + 1 + @intcast(min))
}

View file

@ -1,11 +1,52 @@
stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer} := stn
.{string, memory, buffer, random} := stn;
.{Vec2} := stn.math
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb")
Window := struct {
// TODO: Replace this with widgets
implicit_framebuffer: render.Surface,
width: int,
height: int,
x: int,
y: int,
}
main := fn(): int {
a := buffer.create("XHorizon\0")
// BUG: Backbuffering is disabled
screen := render.init(true)
// Clear the screen to black.
render.clear(screen, render.black)
window := render.new_surface(screen.width / 3, screen.height / 3)
pos := Vec2(int).(100, 100)
color := random.range(render.Color, render.black, render.white)
loop {
// Clear the screen
render.clear(screen, render.black)
// TODO: Read the window buffer here
// TODO: Get windows out of a collection and iter through
//
{
render.clear(window, render.white)
// Apply the image to the screen
render.put_surface(screen, window, pos)
}
// Sync the screen
render.sync(screen)
}
return 0

View file

@ -8,28 +8,28 @@ ignim := @use("../../../libraries/ignim/src/lib.hb");
.{errors} := ignim
main := fn(): int {
windowing_system_buffer := buffer.create("XHorizon\0")
windowing_system_buffer := buffer.search("XHorizon\0")
// TODO: get WindowID
create_window(windowing_system_buffer)
program_name := "Horizon Testing Program\0"
program_version := ignim.version.make_version(0, 1, 0)
engine_name := "None\0"
engine_version := ignim.version.make_version(0, 0, 0)
api_version := ignim.version.make_api_version(0, 1, 0, 0)
// program_name := "Horizon Testing Program\0"
// program_version := ignim.version.make_version(0, 1, 0)
// engine_name := "None\0"
// engine_version := ignim.version.make_version(0, 0, 0)
// api_version := ignim.version.make_api_version(0, 1, 0, 0)
app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version)
// app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version)
create_info := ignim.instance.new_create_info(&app_info)
// create_info := ignim.instance.new_create_info(&app_info)
instance := ignim.instance.void_instance()
// instance := ignim.instance.void_instance()
// TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
ret := ignim.instance.create_instance(&create_info, 0, &instance)
if ret == errors.IncompatibleDriver {
log.error("Driver Incompatible with Vulkan\0")
}
// // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
// ret := ignim.instance.create_instance(&create_info, 0, &instance)
// if ret == errors.IncompatibleDriver {
// log.error("Driver Incompatible with Vulkan\0")
// }
return 0
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

View file

@ -4,16 +4,16 @@ render := @use("../../../../libraries/render/src/lib.hb")
the impostor travels left and loops around the screen */
example := fn(): void {
render.init()
screen := render.init(true)
x := 0
loop {
render.put_rect(.(200 - x, 80), .(430, 380), render.red)
render.put_rect(.(630 - x, 120), .(120, 300), render.red)
render.put_rect(.(200 - x, 460), .(160, 270), render.red)
render.put_rect(.(470 - x, 460), .(160, 270), render.red)
render.put_rect(.(140 - x, 140), .(340, 250), render.cyan)
render.sync()
render.clear(render.black)
render.put_rect(screen, .(200 - x, 80), .(430, 380), render.red)
render.put_rect(screen, .(630 - x, 120), .(120, 300), render.red)
render.put_rect(screen, .(200 - x, 460), .(160, 270), render.red)
render.put_rect(screen, .(470 - x, 460), .(160, 270), render.red)
render.put_rect(screen, .(140 - x, 140), .(340, 250), render.cyan)
render.sync(screen)
render.clear(screen, render.black)
x += 1
}
return

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View file

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

View file

@ -6,12 +6,12 @@ render := @use("../../../../libraries/render/src/lib.hb")
note that this may happen too fast for you to notice... */
example := fn(): void {
render.init()
screen := render.init(true)
color := render.light_cyan
n := @as(u8, 1)
loop {
render.clear(color)
render.sync()
render.clear(screen, color)
render.sync(screen)
if (color.b & 255) == 255 | (color.b & 255) == 0 {
n = -n
}

View file

@ -4,25 +4,31 @@ render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
a cute image bounces around the screen */
bmp := @embed("./able.bmp")
bmp_1 := @embed("./assets/able.bmp")
bmp_2 := @embed("./assets/mini.bmp")
example := fn(): void {
render.init()
image := render.image.from_bmp(@bitcast(&bmp))
screen := render.init(true)
images := [render.Surface; 2].(
render.image.surface_from_bmp(@bitcast(&bmp_1)),
render.image.surface_from_bmp(@bitcast(&bmp_2)),
)
vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100)
width := render.width()
height := render.height()
n := -1
loop {
render.put_image(image, pos)
render.sync()
render.clear(render.black)
image := images[n]
render.put_surface(screen, image, pos)
render.sync(screen)
render.clear(screen, render.black)
if pos.x == 0 | pos.x == width - image.width {
if pos.x == 0 | pos.x == screen.width - image.width {
vel.x = -vel.x
n = -1 - n
}
if pos.y == 0 | pos.y == height - image.height {
if pos.y == 0 | pos.y == screen.height - image.height {
vel.y = -vel.y
n = -1 - n
}
pos += vel

View file

@ -6,18 +6,16 @@ render := @use("../../../../libraries/render/src/lib.hb")
created on a blue background */
example := fn(): void {
render.init()
render.clear(.(100, 50, 0, 255))
width := render.width()
height := render.height()
screen := render.init(true)
render.clear(screen, .(100, 50, 0, 255))
p0 := Vec2(int).(0, 0)
p1 := Vec2(int).(0, height)
loop if p0.y >= height break else {
render.put_line(p0, p1, .(255, 180, 100, 255))
render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255))
p0.y += height >> 6
p1.x += width >> 6
p1 := Vec2(int).(0, screen.height)
loop if p0.y >= screen.height break else {
render.put_line(screen, p0, p1, .(255, 180, 100, 255))
render.put_line(screen, .(screen.width, screen.height) - p0, .(screen.width, screen.height) - p1, .(255, 180, 100, 255))
p0.y += screen.height >> 6
p1.x += screen.width >> 6
}
render.sync()
render.sync(screen)
return
}

View file

@ -2,16 +2,15 @@
render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void {
render.init()
render.doublebuffer(false)
render.clear(render.black)
screen := render.init(false)
render.clear(screen, render.black)
loop {
x := random.range(int, 0, 1024)
y := random.range(int, 0, 768)
r := random.range(int, 0, 255)
g := random.range(int, 0, 75)
b := random.range(int, 0, 155)
render.put_pixel(.(x, y), .(b, g, r, 255))
render.put_pixel(screen, .(x, y), .(b, g, r, 255))
}
return
}

View file

@ -6,24 +6,23 @@ render := @use("../../../../libraries/render/src/lib.hb")
a square that changes colour bounces around the screen */
example := fn(): void {
render.init()
screen := render.init(true)
vel := Vec2(int).(1, 1)
pos := Vec2(int).(100, 100)
width := render.width()
height := render.height()
color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
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(pos, .(100, 100), color)
render.sync()
render.clear(render.black)
render.put_filled_rect(screen, pos, .(side, side), color)
render.sync(screen)
render.clear(screen, render.black)
if pos.x == 0 | pos.x == width - 100 {
if pos.x == 0 | pos.x == screen.width - side {
vel.x = -vel.x
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
color = random.range(render.Color, render.black, render.white)
}
if pos.y == 0 | pos.y == height - 100 {
if pos.y == 0 | pos.y == screen.height - side {
vel.y = -vel.y
color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
color = random.range(render.Color, render.black, render.white)
}
pos += vel

View file

@ -0,0 +1,48 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
.{random} := @use("../../../../libraries/stn/src/lib.hb")
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
the square example bounces around the screen */
example := fn(): void {
screen := render.init(true)
image := render.new_surface(screen.width / 3, screen.height / 3)
vel := Vec2(int).(-1, -1)
pos := Vec2(int).(100, 100)
side := image.width / 8
vel_inner := Vec2(int).(1, 1)
pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2)
color := random.range(render.Color, render.black, render.white)
loop {
render.clear(image, render.black)
render.clear(screen, render.black)
render.put_filled_rect(image, pos_inner, .(side, side), color)
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), render.white)
render.put_surface(screen, image, pos)
render.sync(screen)
if pos_inner.x == 0 | pos_inner.x == image.width - side {
vel_inner.x = -vel_inner.x
color = random.range(render.Color, render.black, render.white)
}
if pos_inner.y == 0 | pos_inner.y == image.height - side {
vel_inner.y = -vel_inner.y
color = random.range(render.Color, render.black, render.white)
}
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
pos_inner += vel_inner
}
return
}

View file

@ -1,8 +0,0 @@
render := @use("../../../../libraries/render/src/lib.hb")
render.mode = render.svga
example := fn(): void {
render.init()
return
}

View file

@ -7,10 +7,10 @@ Vec2 := math.Vec2
with a "target" randomly apperaing in one of them and a "seeker" "catching" it */
example := fn(): void {
render.init()
screen := render.init(true)
width := render.width()
height := render.height()
width := screen.width
height := screen.height
cell_size := 0
range := Vec2(int).(0, 0)
if width > height {
@ -33,32 +33,32 @@ example := fn(): void {
seeker := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y))
loop {
render.clear(render.black)
render.clear(screen, render.black)
target_pixel_coord := target * .(cell_size, cell_size) + .(scroll, scroll)
render.put_trirect(target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red)
render.put_trirect(screen, target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red)
render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red)
render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red)
render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red)
render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red)
render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red)
render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red)
render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red)
render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red)
x := scroll
loop if x > width break else {
render.put_vline(x, 0, height, .(0, 127, 0, 127))
render.put_vline(screen, x, 0, height, .(0, 127, 0, 127))
x += cell_size
}
y := scroll
loop if y > height break else {
render.put_hline(y, 0, width, .(0, 127, 0, 127))
render.put_hline(screen, y, 0, width, .(0, 127, 0, 127))
y += cell_size
}
render.put_hline(seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green)
render.put_vline(seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green)
render.put_hline(screen, seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green)
render.put_vline(screen, seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green)
render.sync()
render.sync(screen)
if seeker.x < target.x {
seeker.x += 1

View file

@ -1,6 +1,3 @@
.{example} := @use("./examples/image.hb")
.{example} := @use("./examples/surface.hb")
main := fn(): void {
@inline(example)
return
}
main := example