Fork me on GitHub
#quil
<
2019-10-10
>
Zac Bir17:10:39

I’ve got an update function that I want to create a circle, expand it to its largest valid size, and hand that back for the draw function.

(defn update [state]
  (loop [circle {:x (* (rand) width) :y (* (rand) height) :r 1}]
    (when (not (is-valid? circle))
      (do
        (conj circles circle)
        circle) ; Hand back our circle to be drawn
      (recur {:x (:x circle) :y (:y circle) :r (inc (:r circle))}))))

Zac Bir18:10:24

However, this function returns nil. What’s the best (both idiomatic and, well, working) approach for what I’m looking for?

Zac Bir18:10:12

(basically, we’re ignoring the incoming state, creating a new circle each time, comparing its validity (not having grown outside the bounds of the canvas, nor overlapping any other circles)

Zac Bir18:10:42

Figured it out. s/when/if/

Zac Bir19:10:26

After more noodling, I’m closer, but my is-valid? function seems to not quite be working 🙂

Zac Bir19:10:44

More likely, it’s my behavior in the loop after I’ve tested.