Jaylib - 3, Basics

John Gabriele


(Previous article: Jaylib - 2, Docs)

I’m learning Jaylib/Raylib myself as I write this, but here are a few morsels I can provide:

Here’s an example of how that all looks:

#!/usr/bin/env janet

(import jaylib :as jl)

(def screen-width  800)
(def screen-height 400)

(defn init-game
  (jl/init-window screen-width
                  "Title Goes Here")
  (jl/set-target-fps 60)

(defn update-game
  (comment "Nothing to update at the moment."))

(defn draw-game
  (let [[x y] (jl/get-mouse-position)]
    (jl/draw-circle-gradient x y 40 :lime :red)))

(defn main
  [& args]
  (while (not (jl/window-should-close))
    (jl/clear-background [0 0 0])

(Please excuse the temporary lack of proper Janet syntax-highlighting here.)

Running this will produce a window where the colorful circle follows your mouse around:

Some comments on that code:

(Next up: Jaylib - 4, The Bouncing Square)

Notice any errors, glaring omissions, or just clumsy wording? Please email me at approximately <jgabriele©fastmail·fm>. Thank you!