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

@ -11,38 +11,36 @@ on Linux and macOS.
** API
High-level API:
- ~F _display width‿height~ creates a window of the given dimensions
and displays its left operand. ~F~ should be a function returning a
color as an RGB triplet in the (0,1) range, and taking a list of two
elements ~x‿y~, where ~x~ and ~y~ are the pixel coordinates.
Low-level API:
- ~OpenWindow w‿h‿t~ opens a window of width ~w~ and height ~h~, with
title ~t~. Returns a window handle.
- ~CloseWindow w~ closes a window given its handle ~w~.
- ~F _render w~ runs the function ~F~ at each coordinate of the window
~w~ and set the corresponding pixel color. ~F~ should be a function
returning a color as an RGB triplet in the (0,1) range, and taking a
list of three elements ~x‿y‿t~, where ~x~ and ~y~ are the pixel
coordinates and ~t~ is the time.
~w~ and set the corresponding pixel color. ~F~ is a function with
the same arguments as for ~_display~.
** Example
See [[./example.bqn][example.bqn]].
#+begin_src bqn
f←•Import "fenster.bqn"
f←•Import"fenster.bqn"
size←500
w←f.OpenWindow size‿size‿"bqn-fenster example"
Rainbow←{𝕊x‿y‿t:
Rainbow←{𝕊x‿y:
x‿y↩x‿y÷size
t↩(100|t)÷100
h←(x+y)÷2
f.HSVtoRGB⟨360×h,1,1⟩
}
Rainbow f._render w
•Delay 3
f.CloseWindow w
Rainbow f._display size‿size
#+end_src
[[./example.png]]