Skip to content

Commit

Permalink
extract the breadth first walk of the tree into it's own function
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Feb 7, 2024
1 parent 8359a2e commit c296bdd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/shimmers/sketches/quadtrace.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@
(update :tree remove-point)
(update :tree g/add-point p cursor))))

(defn draw [{:keys [t tree]}]
(defn breadth-seq [tree]
(sort-by (fn [n] (:depth (meta n)))
(tree-seq (fn [t] (not-empty (spatialtree/get-children t)))
(fn [t] (map #(vary-meta % assoc :depth (inc (:depth (meta t))))
(remove nil? (spatialtree/get-children t))))
(vary-meta tree assoc :depth 0))))

(defn draw [{:keys [tree]}]
(q/background 1.0)
(q/ellipse-mode :radius)
(q/stroke-weight 0.66)
(q/stroke 0.0 0.1)
(q/fill 0.2 0.1)
(doseq [node (sort-by (fn [n] (:depth (meta n)))
(tree-seq (fn [t] (not-empty (spatialtree/get-children t)))
(fn [t] (map #(vary-meta % assoc :depth (inc (:depth (meta t))))
(remove nil? (spatialtree/get-children t))))
(vary-meta tree assoc :depth 0)))]
(doseq [node (breadth-seq tree)]
(cq/rectangle (g/bounds node))))

(defn page []
Expand Down

0 comments on commit c296bdd

Please sign in to comment.