Skip to content

Commit

Permalink
add ground connection component
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Dec 12, 2024
1 parent 655adf2 commit 623043e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/shimmers/sketches/circuit_diagrams.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,35 @@
(for [face out]
(connector face (v/+polar center radius (face-angle face center)))))))))

(defn bar [pt r angle]
(vary-meta (gl/line2 (v/+polar pt r (- angle (* 0.25 eq/TAU)))
(v/+polar pt r (+ angle (* 0.25 eq/TAU))))
assoc :stroke-width 2.0))

(defmethod draw-component :ground
[{:keys [shape faces]}]
(let [center (g/centroid shape)
size (min (g/width shape) (g/height shape))]
(mapcat (fn [{:keys [connected] :as face}]
(when connected
(let [angle (face-angle face center)
pt (v/+polar center (* 0.17 size) angle)
pt2 (v/+polar center (* 0.14 size) angle)
pt3 (v/+polar center (* 0.11 size) angle)]
[(connector face pt)
(bar pt (* 0.06 size) angle)
(bar pt2 (* 0.04 size) angle)
(bar pt3 (* 0.02 size) angle)])))
faces)))

(defn draw [{:keys [shape faces] :as component}]
(concat [shape]
(mapcat draw-face faces)
(draw-component component)))

(defn make-component [shape]
{:shape shape
:kind (dr/weighted {:wire 1 :orb 10})
:kind (dr/weighted {:wire 1 :orb 1 :ground 1})
:faces (face-normals shape)})

(defn shapes []
Expand Down

0 comments on commit 623043e

Please sign in to comment.