Defining function that calls a quil function in a separate namespace

14 views
Skip to first unread message

Jason Fabris

unread,
Jan 1, 2020, 2:30:02 PM1/1/20
to clj-processing

Hi,

I'm making a thing where a bunch of "pacers" do their thing in the display window.

To keep myself organized, I was trying to split out everything to do with those pacers into a separate file...

In core.clj, my namespace declaration looks like this:

(ns conflicting_frcs_v1.core
  (:require [quil.core :as q]
            [quil.middleware :as m]
            [conflicting_frcs_v1.pacer :as p]
            [conflicting_frcs_v1.math.vector :as mv]))

Then, in the pacer file, I have a bunch of functions that work. But.. I want to define how the pacer displays. I have this function:
(defn display-pacer [p]
  (let [[x y] (:location p)]
    (q/ellipse x y 10 10)))

When I call that from draw-state in core.clj, I get errors. I am assuming this has something to do with the "only works inside sketch functions" limitation of ellipse? So, I'm trying to understand why that is, and how I can get around it.
Ideally, I'd like to keep the draw-state pretty minimal and define the implementation of how the pacer is displayed in its own file.

I tried requiring quil.core in the pacer file too, but that doesn't seem like it should work (and it doesn't!).

So, just looking to understand this behaviour so I can figure out how this all works. Thanks!
Jason

Mikita Belahlazau

unread,
Jan 1, 2020, 11:17:49 PM1/1/20
to clj-processing
Hi Jason

What kind of errors do you get when you call display-pacer from inside draw-state? The scenario you described (calling functions defined in another namespace) should work just fine. The "only works inside sketch functions" part you mention means that sketch or defsketch call must be higher in stacktrace. So the following should work fine;



(ns some.util 
  (:require [quil.core :as q]))

(defn draw-circle []
  (q/circle 0 0 100 100))




(ns some.core
  (:require [quil.core :as q
             some.util :as u]))

(defn draw []
  (u/draw-circle))

(defsketch ...
  :draw draw))


Mikita

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clj-processing/027c8798-2c5d-4054-a250-cfcf8a7520b6%40googlegroups.com.

Jason Fabris

unread,
Jan 18, 2020, 1:07:57 PM1/18/20
to clj-processing
Thanks! It works now. I am not quite sure what I did wrong. I think I probably forgot to to evaluate the second namespace file. It's a mystery. 
To unsubscribe from this group and stop receiving emails from it, send an email to clj-pro...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages