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))}))))
However, this function returns nil. What’s the best (both idiomatic and, well, working) approach for what I’m looking for?
(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)
https://gist.github.com/zacbir/508e4762a1be8f42b22c68a180938bc8
Figured it out. s/when/if/
After more noodling, I’m closer, but my is-valid?
function seems to not quite be working 🙂
More likely, it’s my behavior in the loop
after I’ve tested.