Fix radii and get rid of most self-intersections
This commit is contained in:
parent
ffc4bff955
commit
a0c302939a
1 changed files with 32 additions and 21 deletions
|
|
@ -15,13 +15,13 @@
|
||||||
|
|
||||||
;; parameters to influence how the end result looks
|
;; parameters to influence how the end result looks
|
||||||
|
|
||||||
(def start-size 12.0)
|
(def start-size 7.0)
|
||||||
(def min-size 8.0)
|
(def min-size 4.0)
|
||||||
(def shrink 0.8) ;; factor by which size decreases at each step
|
(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 max-path-length 30) ;; how long are the strings of nodes?
|
||||||
(def num-paths 25) ;; how many strings should be generated max?
|
(def num-paths 45) ;; how many strings should be generated max?
|
||||||
|
|
||||||
;; all nodes look like this: {:shape circ, :direction vec2}
|
;; all nodes look like this: {:shape circ, :direction vec2}
|
||||||
|
|
||||||
|
|
@ -45,17 +45,26 @@
|
||||||
(g/scale-size circ 1.5)))))
|
(g/scale-size circ 1.5)))))
|
||||||
(first)))
|
(first)))
|
||||||
|
|
||||||
(defn next-node [quadtree cur]
|
(defn next-node [quadtree path]
|
||||||
(->> (repeatedly 10 (fn []
|
(let [cur (peek path)]
|
||||||
(-> (update cur :shape (fn [c]
|
(->> (repeatedly 10 (fn []
|
||||||
(-> (update c :r #(Math/max (* % shrink) min-size))
|
(-> (update cur :shape (fn [c]
|
||||||
(update :p #(g/translate % (m/* (:direction cur) (:r c)))))))
|
(-> (update c :r #(Math/max (* % shrink) min-size))
|
||||||
(update :direction wobble))))
|
(update :p #(g/translate % (m/* (:direction cur) (* 2 (:r c))))))))
|
||||||
(filter (fn [node]
|
(update :direction wobble))))
|
||||||
(when-not (nice-place? quadtree node)
|
(filter (fn [node]
|
||||||
(prn node))
|
(and (nice-place? quadtree node)
|
||||||
(nice-place? quadtree node)))
|
;; avoid self-intersections
|
||||||
(first)))
|
(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
|
;; let's generate different paths of hyphae, each a most 50 nodes long
|
||||||
|
|
@ -63,14 +72,15 @@
|
||||||
(defn make-path [quadtree]
|
(defn make-path [quadtree]
|
||||||
(when-let [seed (pick-start quadtree)]
|
(when-let [seed (pick-start quadtree)]
|
||||||
(->>
|
(->>
|
||||||
(iterate (fn [[head & _ :as path]]
|
(iterate (fn [path]
|
||||||
(if-let [next (next-node quadtree head)]
|
(if-let [next (next-node quadtree path)]
|
||||||
(conj path next)
|
(conj path next)
|
||||||
path))
|
path))
|
||||||
(list seed))
|
(list seed))
|
||||||
(partition 2)
|
(partition 2)
|
||||||
(filter (fn [[a b]] (= a b)))
|
(filter (fn [[a b]] (= a b)))
|
||||||
(ffirst))))
|
(ffirst)
|
||||||
|
(take-last max-path-length))))
|
||||||
|
|
||||||
(def paths
|
(def paths
|
||||||
(let [qt (st/quadtree bounds)]
|
(let [qt (st/quadtree bounds)]
|
||||||
|
|
@ -92,7 +102,7 @@
|
||||||
|
|
||||||
(doseq [path paths
|
(doseq [path paths
|
||||||
{{[x y] :p r :r} :shape} path]
|
{{[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))
|
#_(qd/draw-scene! scene))
|
||||||
|
|
||||||
(when-not (resolve 'thirty-four)
|
(when-not (resolve 'thirty-four)
|
||||||
|
|
@ -105,4 +115,5 @@
|
||||||
:setup setup
|
:setup setup
|
||||||
:update identity
|
:update identity
|
||||||
:draw draw-state
|
:draw draw-state
|
||||||
:middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode]))
|
:middleware [qm/pause-on-error #_(screenshottable) qm/fun-mode])
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue