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?
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.
Scratch that. Loading it during setup seems to do the trick. I'll play with it some more, to see the limitations.
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])
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) http://quil.info/sketches/show/baf36ac7134ea3fa2ba0f6eca525a8cf2e2a08a65e6dc5531c4727ecf4801d4e