This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-10
Channels
- # announcements (3)
- # babashka (3)
- # beginners (83)
- # calva (1)
- # cider (19)
- # clojure (131)
- # clojure-austin (4)
- # clojure-dev (3)
- # clojure-europe (49)
- # clojure-greece (2)
- # clojure-italy (8)
- # clojure-losangeles (18)
- # clojure-nl (14)
- # clojure-poland (1)
- # clojure-uk (65)
- # clojurescript (28)
- # core-async (7)
- # core-logic (3)
- # cursive (2)
- # data-science (1)
- # datomic (98)
- # defnpodcast (1)
- # figwheel-main (6)
- # fulcro (95)
- # graphql (5)
- # hoplon (7)
- # kaocha (1)
- # lein-figwheel (6)
- # luminus (1)
- # nyc (1)
- # off-topic (21)
- # pedestal (1)
- # quil (8)
- # re-frame (15)
- # reagent (106)
- # reitit (15)
- # shadow-cljs (158)
- # sim-testing (1)
- # spacemacs (17)
- # sql (25)
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)