Skip to content

Instantly share code, notes, and snippets.

Saikyun / janet_stepping_poc.janet
Created Apr 24, 2021
poc for step debugging janet
View janet_stepping_poc.janet
(defmacro line-number
(def [l c] (tuple/sourcemap (dyn :macro-form ())))
(defn add []
(def a 10)
(+ a a))
#=> turns into
View queues.janet
(def click-queue (ev/chan 4))
(defn ev/check
(when (pos? (ev/count chan))
(ev/take chan)))
(defn ev/push
[chan v]
(when (ev/full chan)
Saikyun /
Last active Apr 19, 2021
Different ways to handle interaction and rendering

Different ways to handle interaction and rendering

A list of different ways to deal with interactions (mouse clicks, keyboard input, network events) and rendering of graphics (gui elements, games).

All example code is written in janet.

FRP (old elm style)


Inspired by how elm used to do FRP (

View fiber_vs_function_call.janet
(defmacro timeit2
Time the execution of `form` using `os/clock` before and after,
and print the result to stdout. returns: result of executing `form`.
Uses `tag` (default "Elapsed time:") to tag the printout.
[form &opt tag]
(default tag "Elapsed time:")
(with-syms [start result end]
View messy_frp.janet
(defonce pushers @[])
(defonce pullers @[])
(array/clear pushers)
(array/clear pullers)
(defonce click-buffer @[])
(array/clear click-buffer)
(defonce move-buffer @[])
View mario_frp.janet
(def mario @{:x 0 :y 0 :vx 0 :vy 0})
(defn physics
[dt mario]
(-> mario
(update :x + (* (mario :vx) dt))
(update :y + (* (mario :vy) dt))))
(defn walk
[x mario]
View handle_input_with_context.janet
# two kinds of renders
(var mouse-stolen false)
(defn mouse-button-down?
(if ((dyn :context) :captured-mouse)
(and (not mouse-stolen)
(raylib/mouse-button-down? k))))
Saikyun / caching.janet
Created Apr 13, 2021
Caching with hopefully nice ui.
View caching.janet
(defn invalidate!
"Invalidates the cache, i.e. forces it to rerender next `cached-render` call."
[& [c]]
(default c (dyn :cache))
(put c :valid false))
(defn update!
"Like update, but also runs invalidate!"
[& args]
(update ;args)
View Input handling
41.09 How to handle focus
Kinds of focus
- Mouse clicks
- Hover
- Drag
- Keyboard handling
- (Re)rendering
How to detect focus
View anim_using_fiber.janet
(use ./build/jaylib)
(init-window 800 600 "Chart")
(set-target-fps 60)
(def current-animations @{})