Skip to content

Commit

Permalink
add functional debug view toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed May 25, 2024
1 parent 2a564d5 commit 0d8e016
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/shimmers/sketches/patterns_shifted.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
[thi.ng.geom.vector :as gv]
[thi.ng.math.core :as tm]))

(defonce ui-state (ctrl/state {:debug false}))
(defonce defo (debug/state []))

(def width 800)
(def height 600)
(def bounds (rect/rect 0 0 width height))
Expand All @@ -29,6 +31,7 @@
(poly/regular-n-gon n r)))

(defn gen-shapes [size shape n]
(reset! defo [])
(loop [structure [shape]
faces (set (g/edges shape))
annotation []]
Expand Down Expand Up @@ -59,33 +62,34 @@
(disj faces face)
annotation))))))

(defn shapes []
(let [size (* 0.08 height)
starting (vary-meta (g/center (random-shape size)
(rv 0.5 0.5))
assoc :stroke "#772222")
{:keys [structure annotation faces]}
(gen-shapes size starting 32)]
(conj (concat structure annotation)
(csvg/group {:stroke-width 2.0}
(mapv (fn [[p q]] (gl/line2 p q)) faces)))))
(defn shapes [{:keys [structure annotation faces]}]
(conj (concat structure (if (:debug @ui-state) annotation []))
(csvg/group {:stroke-width 2.0}
(mapv (fn [[p q]] (gl/line2 p q)) faces))))

(defn scene []
(defn scene [generated]
(csvg/svg-timed {:width width
:height height
:stroke "black"
:fill "none"
:stroke-width 0.5}
(reset! defo [])
(shapes)))
(shapes generated)))

(defn page []
(fn []
[sketch/with-explanation
[:div.canvas-frame [scene]]
[view-sketch/generate :patterns-shifted]
[:div.readable-width
[debug/display defo]]]))
(let [size (* 0.08 height)
starting (vary-meta (g/center (random-shape size)
(rv 0.5 0.5))
assoc :stroke "#772222")
generated (gen-shapes size starting 32)]
(fn []
[sketch/with-explanation
[:div.canvas-frame [scene generated]]
[:div.flexcols
[view-sketch/generate :patterns-shifted]
[:div.readable-width
[ctrl/checkbox ui-state "Debug" [:debug]]
(when (:debug @ui-state)
[debug/display defo])]]])))

(sketch/definition patterns-shifted
{:created-at "2024-05-23"
Expand Down

0 comments on commit 0d8e016

Please sign in to comment.