From 9b36c0ca8bb0df5829a7ab69e0c07f2530d29d3e Mon Sep 17 00:00:00 2001 From: Charles Comstock Date: Sun, 15 Dec 2024 20:09:58 -0600 Subject: [PATCH] start separating logic for connection types from face connections --- src/shimmers/sketches/circuit_diagrams.cljs | 42 +++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/shimmers/sketches/circuit_diagrams.cljs b/src/shimmers/sketches/circuit_diagrams.cljs index 797376ea..0b743a8c 100644 --- a/src/shimmers/sketches/circuit_diagrams.cljs +++ b/src/shimmers/sketches/circuit_diagrams.cljs @@ -31,22 +31,32 @@ (gv/vec2 (* width x) (* height y))) ;; FIXME: ensure at least one pass through connection for resistor/wire/capacitor +;; FIXME: face-normals needs to take shape/kind to avoid adding connection types for orbs (defn face-normals [polygon] - (->> - polygon - g/edges - (map-indexed - (fn [i [p q]] - (let [kind (dr/weighted {:wire 3 :ground 1 :resistor 2 :capacitor 2})] - (merge - {:id i - :kind kind - :edge [p q] - :connected (dr/weighted {false 3 true 2})} - (case kind - :resistor - {:params {:resistor-steps (dr/random-int 6 11)}} - {}))))))) + (let [faces (->> + polygon + g/edges + (map-indexed + (fn [i [p q]] + {:id i + :edge [p q] + :connected (dr/weighted {false 3 true 2})}))) + distribution (case (count (filter :connected faces)) + 0 {} + 1 {:ground 1} + 2 (if (dr/chance 0.25) + {:ground 1} + {:wire 3 :resistor 2 :capacitor 2}) + {:wire 3 :ground 1 :resistor 2 :capacitor 2})] + (for [face faces] + (if (:connected face) + (let [kind (dr/weighted distribution)] + (merge (assoc face :kind kind) + (case kind + :resistor + {:params {:resistor-steps (dr/random-int 6 11)}} + {}))) + face)))) (defn face-center [{[p q] :edge}] (tm/mix p q 0.5)) @@ -109,7 +119,7 @@ pt (v/+polar center (* 0.17 size) angle) pt2 (v/+polar center (* 0.14 size) angle) pt3 (v/+polar center (* 0.11 size) angle)] - (csvg/group {} + (csvg/group {:stroke-width 2.0} (connector face pt) (bar pt (* 0.06 size) angle) (bar pt2 (* 0.04 size) angle)