Simplify the API

This commit is contained in:
Dimitri Lozeve 2024-11-11 22:24:22 +01:00
parent b7203383a7
commit 9c95b1a5ab
5 changed files with 59 additions and 25 deletions

View file

@ -1,7 +1,10 @@
FensterLoop,
OpenWindow,
CloseWindow,
_render,
RenderArray
_display,
Black,
White,
Gray,
@ -11,6 +14,8 @@
HSVtoRGB
## FFI functions
FensterFFI"lib.so"•FFI
fensterOpenFensterFFI"i8""fenster_open"">*:i8"
@ -24,7 +29,12 @@ fensterGetWidth←FensterFFI"u32"‿"fenster_get_width"‿">*:i8"
fensterGetHeightFensterFFI"u32""fenster_get_height"">*:i8"
fensterGetPixelFensterFFI"u32""fenster_get_pixel""*:i8""u32""u32"
fensterSetPixelFensterFFI"""fenster_set_pixel""*:i8""u32""u32""u32"
fensterSetArrayFensterFFI"""fenster_set_array""*:i8""u32""u32""u32""u32""*u32"
## Low-level functions
# Open a window with given width, height, and title
# Returns the window's handle.
OpenWindow{𝕊wht:
fFensterInitw,h,1+t,t@
FensterOpen f
@ -32,17 +42,19 @@ OpenWindow←{𝕊w‿h‿t:
f
}
# Close a window.
CloseWindow{𝕊f:
FensterClose f
FensterLoop f
}
# Render a function in the window.
# The function should take a list x‿y of coordinates and return an r‿𝕘‿b color.
_render{Func _𝕣 f:
wFensterGetWidth f
hFensterGetHeight f
tFensterTime
{𝕊xy:
rgbFunc xyt
rgbFunc xy
c+´(2563)×rgb×255
FensterSetPixel fxyc
}¨(w)h
@ -50,6 +62,24 @@ _render←{Func _𝕣 f:
f
}
# Render an array directly.
RenderArray{buf𝕊f:
bufwbufhbuf
FensterSetArrayf,0,0,bufw,bufh,buf
}
## High-level function
# Open a window, render a function in it, and wait for the user to close it.
_display{Func _𝕣 wh:
winOpenWindow wh"bqn-fenster"
Func _render win
•_while_(¬FensterLoop)win
CloseWindow win
}
## Utilities
Black000˙
White111˙
Gray{𝕩𝕩𝕩}