Skip to content

Commit

Permalink
draw great arcs correctly for orb connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Dec 11, 2024
1 parent bc6aa76 commit b3b60d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/shimmers/math/geometry/arc.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
svg/ISVGConvert
(as-svg [_ opts]
(csvg/path [[:M (v/+polar p r t0)]
[:A [r r] 0.0 0 1 (v/+polar p r t1)]]
[:A [r r] 0.0 (if (> (- t1 t0) math/PI) 1 0) 1
(v/+polar p r t1)]]
opts)))

;; Forces arcs to be clockwise from t0 to t1
Expand Down
14 changes: 9 additions & 5 deletions src/shimmers/sketches/circuit_diagrams.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[shimmers.math.equations :as eq]
[shimmers.math.geometry.arc :as arc]
[shimmers.math.geometry.polygon :as poly]
[shimmers.math.vector :as v]
[shimmers.sketch :as sketch :include-macros true]
[thi.ng.geom.circle :as gc]
[thi.ng.geom.core :as g]
Expand Down Expand Up @@ -60,25 +61,28 @@
(connector face center))) faces))
:orb
(let [center (g/centroid shape)
radius 18.0
[in & out] (filter :connected faces)]
(into (when in
[(connector in center)
(vary-meta (gc/circle center 6.0)
assoc :stroke-width 2.0)])
(when (seq out)
(into [(let [margin (* eq/TAU 0.66 (/ 1.0 (inc (count faces))))
(into [(let [margin (* eq/TAU 0.75 (/ 1.0 (inc (count faces))))
t0 (- (g/heading (tm/- (face-center (first out)) center)) margin)
t1 (+ (g/heading (tm/- (face-center (last out)) center)) margin)]
(vary-meta (arc/arc center 18.0 t0 t1)
(vary-meta (arc/arc center radius t0 t1)
assoc :stroke-width 2.0
:fill "none"))]
:fill "none"))
(gc/circle (tm/mix center (face-center (first out)) 0.33) 4.0)
(gc/circle (tm/mix center (face-center (last out)) 0.66) 4.0)]
(for [face out]
(connector face (tm/mix center (face-center face) 0.1))))))))
(connector face (v/+polar center radius (g/heading (tm/- (face-center face) center))))))))))
(mapcat draw-face faces)))

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

(defn shapes []
Expand Down

0 comments on commit b3b60d2

Please sign in to comment.