quil

narimiran 2025-05-26T15:35:18.212149Z

I've been using quil off and on for quite some time, and one thing I never managed to get to work is...... loading and displaying images. I tried to follow the examples from the docs: http://quil.info/api/image/loading-and-displaying but with no success. Does anybody have a working example of it?

narimiran 2025-05-29T10:50:06.485099Z

Thanks for the example! I'm trying to have this in the m/fun-mode, and avoid q/set-state! , i.e. call directly (q/image (q/load-image url) 0 0), but can't make it work.

narimiran 2025-05-29T10:54:42.962479Z

Scratch that. Loading it during setup seems to do the trick. I'll play with it some more, to see the limitations.

Charles Comstock 2025-05-30T04:58:04.960429Z

Should work to q/load-image in setup, but you will likely still need that q/loaded? check, so it waits to draw after the image url is downloaded. Something like this should work though:

(defn setup [] {:image (q/load-image *url*))

(defn draw [{:keys [image]}]
  (when (q/loaded? image)
    (q/image image 0 0)))

(q/defsketch ex
  :setup #'setup
  :draw #'draw
  :middleware [m/fun-mode])

p-himik 2025-05-26T16:23:15.598029Z

I just mashed up two examples together:

(ns my.core
  (:require [quil.core :as q :include-macros true]))

(defn setup []
  (let [url ""]
    (q/set-state! :image (q/load-image url))))

(defn draw []
  (q/background 255)
  (let [im (q/state :image)]
    (when (q/loaded? im) (q/image im 0 0))))

(q/defsketch my
  :host "host"
  :size [500 500]
  :setup setup
  :draw draw)