Janet bindings to Raylib. The bindings are faithful to the original C API, especially where it makes sense, but function names have been "lispified" (kebab case, question marks instead of the word "Is", etc.). See api.txt for an overview of which API functions have been ported.
(use jaylib)
(init-window 100 100 "Test Game")
(set-target-fps 60)
(hide-cursor)
(while (not (window-should-close))
(begin-drawing)
(clear-background [0 0 0])
(let [[x y] (get-mouse-position)]
(draw-circle-gradient (math/floor x) (math/floor y) 31.4 :lime :red)
(draw-poly [500 200] 5 40 0 :magenta)
(draw-line-bezier
[(- x 100) y]
[(+ x 100) (+ y 50)]
4 :pink)
(draw-line-ex
[x (- y 10)]
[x (+ y 10)]
4 :sky-blue)
(draw-line-strip
[[x 0] [x 100] [50 y] [10 180]]
:ray-white))
(end-drawing))
(close-window)
Clone the repo with submodules, or use git submodule update --init --recursive
.
jpm build
This should compile build\jaylib.so
on nix systems or build\jaylib.dll
on Windows, which you can import in
a janet repl.
(use ./build/jaylib)
You no longer need to put any dependencies on your system to get jaylib, it should autodetect and build right out of the box.
[sudo] jpm install https://github.com/janet-lang/jaylib.git
The best documentation for Jaylib is the documentation for raylib. You can also find extensive examples for Raylib at https://www.raylib.com/examples.html.
The C API of Raylib has been mirrored in Janet as predictably as I can while making it pleasant to use. See api.txt for functions that have been implemented. The rules for binding a Raylib function to a Janet function are as follows:
PascalCase
; the corresponding janet functions are in kebab-case
.[x y]
. I prefer an representation of vectors rather than named components (0 1 2 vs. x y z), as
it makes many algorithms simpler, and the representation more efficient.CAMERA_MODE_ORTHOGRAPHIC
becomes just :orthographic
, but will only work in a context where the API expects a camera mode.Colors can be specified a few different ways:
:white
, :green
, :black
, or :raywhite
. These color constants come from raylib.0x00FF00FF
is green, 0xFFFFFFFF
is white, etc. Remember to always include
the alpha. 0xFFFFFF
is cyan, not white.[x y]
, [x y z]
, or [x y z w]
.Instantiate a Camera2D or Camera3D with the camera-2d
and camera-3d
functions. Since these types
are expected to constructed manually in the C API, Jaylib provides functions for initializing these structs.
They take a variable number of keyword arguments that correspond to the structure arguments. Missing arguments
will have a fallback to sensible defaults, such as 0.
(def cam (camera-3d :target [0 3 0]
:up [0 1 0]
:fovy 60
:type :perspective
:position [6 3 6]))
In addition to the functions mapping directly to Raylib functions, the following have been implemented in Jaylib:
Image -> Vector2
Extract width and height from an Image
.
'Font -> Texture2D'
Extracts the 'Texture2D' of a given 'Font'.