Fix radii and get rid of most self-intersections

This commit is contained in:
arne 2022-12-18 18:04:37 +01:00
commit a0c302939a

View file

@ -15,13 +15,13 @@
;; parameters to influence how the end result looks
(def start-size 12.0)
(def min-size 8.0)
(def start-size 7.0)
(def min-size 4.0)
(def shrink 0.8) ;; factor by which size decreases at each step
(def spaciousness 2.0) ;; size of neighbor-check for each node
(def spaciousness 2.5) ;; size of neighbor-check for each node
(def max-path-length 50) ;; how long are the strings of nodes?
(def num-paths 25) ;; how many strings should be generated max?
(def max-path-length 30) ;; how long are the strings of nodes?
(def num-paths 45) ;; how many strings should be generated max?
;; all nodes look like this: {:shape circ, :direction vec2}
@ -45,17 +45,26 @@
(g/scale-size circ 1.5)))))
(first)))
(defn next-node [quadtree cur]
(->> (repeatedly 10 (fn []
(-> (update cur :shape (fn [c]
(-> (update c :r #(Math/max (* % shrink) min-size))
(update :p #(g/translate % (m/* (:direction cur) (:r c)))))))
(update :direction wobble))))
(filter (fn [node]
(when-not (nice-place? quadtree node)
(prn node))
(nice-place? quadtree node)))
(first)))
(defn next-node [quadtree path]
(let [cur (peek path)]
(->> (repeatedly 10 (fn []
(-> (update cur :shape (fn [c]
(-> (update c :r #(Math/max (* % shrink) min-size))
(update :p #(g/translate % (m/* (:direction cur) (* 2 (:r c))))))))
(update :direction wobble))))
(filter (fn [node]
(and (nice-place? quadtree node)
;; avoid self-intersections
(every? (fn [other]
;; (prn other)
;; (prn (g/dist (-> node :shape :p) (-> other :shape :p)))
;; (prn )
(> (g/dist (-> node :shape :p) (-> other :shape :p))) (+ (-> node :shape :r) (-> other :shape :r))) path))))
(first))))
(comment
(make-path (st/quadtree bounds))
)
;; let's generate different paths of hyphae, each a most 50 nodes long
@ -63,14 +72,15 @@
(defn make-path [quadtree]
(when-let [seed (pick-start quadtree)]
(->>
(iterate (fn [[head & _ :as path]]
(if-let [next (next-node quadtree head)]
(iterate (fn [path]
(if-let [next (next-node quadtree path)]
(conj path next)
path))
(list seed))
(partition 2)
(filter (fn [[a b]] (= a b)))
(ffirst))))
(ffirst)
(take-last max-path-length))))
(def paths
(let [qt (st/quadtree bounds)]
@ -92,7 +102,7 @@
(doseq [path paths
{{[x y] :p r :r} :shape} path]
(q/ellipse x y r r))
(q/ellipse x y (* 2 r) (* 2 r)))
#_(qd/draw-scene! scene))
(when-not (resolve 'thirty-four)
@ -105,4 +115,5 @@
:setup setup
:update identity
:draw draw-state
:middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode]))
:middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode])
)