Skip to content

Commit

Permalink
support modulating time param for table and pendulum per axis
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Jan 23, 2024
1 parent 458f869 commit 45ad21d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/shimmers/sketches/harmonograph.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[thi.ng.math.core :as tm]))

(defonce ui-state
(ctrl/state {:table [1 1]
:pendulum [1.001 3]
(ctrl/state {:table [1 1 1 1]
:pendulum [1.001 3 1 1]
:pen [1 2]
:pen-phase [1 3]
:dampen-rate 0.15
Expand All @@ -21,16 +21,20 @@
:pen-modulation false}))

(defn ui-controls []
(ctrl/container
[:<>
[:h3 "Parameters"]
[:div.flexcols
[:div {:style {:width "8em"}} "Table Ratio"]
(ctrl/numeric ui-state "N" [:table 0] [0 32 0.001])
(ctrl/numeric ui-state "D" [:table 1] [1 16 0.1])]
(ctrl/numeric ui-state "D" [:table 1] [1 16 0.1])
(ctrl/numeric ui-state "dt-x" [:table 2] [0.001 10 0.001])
(ctrl/numeric ui-state "dt-y" [:table 3] [0.001 10 0.001])]
[:div.flexcols
[:div {:style {:width "8em"}} "Pendulum Ratio"]
(ctrl/numeric ui-state "N" [:pendulum 0] [0 32 0.001])
(ctrl/numeric ui-state "D" [:pendulum 1] [1 16 0.1])]
(ctrl/numeric ui-state "D" [:pendulum 1] [1 16 0.1])
(ctrl/numeric ui-state "dt-x" [:pendulum 2] [0.001 10 0.001])
(ctrl/numeric ui-state "dt-y" [:pendulum 3] [0.001 10 0.001])]
[:div {:style {:width "16em"}}
(ctrl/numeric ui-state "Dampen Rate" [:dampen-rate] [0.01 0.5 0.01])
(ctrl/numeric ui-state "Dampen Limit" [:dampen-limit] [0.01 0.2 0.01])
Expand All @@ -47,7 +51,7 @@
(ctrl/numeric ui-state "N" [:pen-phase 0] [0 32 0.001])
(ctrl/numeric ui-state "D" [:pen-phase 1] [1 16 0.1])]])

[:em "(updates after restart)"]))
[:em "(updates after restart)"]])

(defn dampen [lambda t]
(Math/exp (* (- lambda) t)))
Expand Down Expand Up @@ -77,8 +81,11 @@
(apply q/point (v/polar (* 0.3 (q/height) k) (* (/ 1 6) t)))))

(defn draw
[{:keys [t dplat dpend dampen-rate dampen-limit modulate-stroke
pen-modulation dpen dpen-phase]}]
[{:keys [t dplat dpend
dampen-rate dampen-limit modulate-stroke
pen-modulation dpen dpen-phase]
[_ _ table-dxt table-dyt] :table
[_ _ pendulum-dxt pendulum-dyt] :pendulum}]
(q/stroke-weight 0.33)
(dotimes [i 1000]
(let [t (+ (* 4.0 t) (/ i 200))
Expand All @@ -87,15 +94,15 @@
(q/no-loop)
(q/with-translation
[(tm/+ (cq/rel-vec 0.5 0.5)
(gv/vec2 (* 0.225 (q/height) k (Math/cos (* 1 dplat t)))
(* 0.225 (q/height) k (Math/sin (* 1 dplat t)))))]
(gv/vec2 (* 0.225 (q/height) k (Math/cos (* table-dxt dplat t)))
(* 0.225 (q/height) k (Math/sin (* table-dyt dplat t)))))]
(when modulate-stroke
(modular-stroke t))
(when (or (not pen-modulation)
(> (Math/sin (+ (* dpen t) (* 2 (Math/sin (* dpen-phase t))))) 0))
(apply q/point
(gv/vec2 (* 0.225 (q/height) k (Math/cos (* 1 dpend t)))
(* 0.225 (q/height) k (Math/sin (* 1 dpend t)))))))))))
(gv/vec2 (* 0.225 (q/height) k (Math/cos (* pendulum-dxt dpend t)))
(* 0.225 (q/height) k (Math/sin (* pendulum-dyt dpend t)))))))))))

(defn page []
[sketch/with-explanation
Expand Down

0 comments on commit 45ad21d

Please sign in to comment.