HomeMathEmailBlogGitHub

Clojure graphics

2023-06-14

For my traveling salesman kata, I'm making a UI to be able to easily pick points and visualize the algorithm.

I chose the Quil graphics library which works really well and is very simplistic. All I had to do is add Quil as a dependency and add the following code with q as the namespace for Quil:

(defn setup []
  (q/frame-rate 10)
  (q/background 200))

(defn draw []
  (q/clear)
  (q/ellipse 200 150 10 10))

(q/defsketch example
  :title "Quil Example"
  :settings #(q/smooth 2)
  :setup setup
  :draw draw
  :size [400 300])

The setup function is called once at the beginning of the program. draw is called every frame (at 10 frames per second as defined in the setup function). Right now it just draws a circle of radius 10 in the middle of the window. Finally, the defsketch defines attributes of the window like size and title.