Skip to content

Commit

Permalink
extract phase-sin from envelope-collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Dec 6, 2024
1 parent db94f62 commit 9cf56b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/shimmers/math/equations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
(defn tan-tau ^double [^double t]
(math/tan (* TAU t)))

(defn phase-sin
^double [^double r ^double t ^double phase]
(math/sin (* TAU (+ (* r t) phase))))

(defn sqr [x]
(* x x))

Expand Down
24 changes: 10 additions & 14 deletions src/shimmers/sketches/envelope_collapse.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
(assoc state
:t (seconds)))

(defn tsin
^double [^double r ^double t ^double phase]
(math/sin (* eq/TAU (+ (* r t) phase))))

(defn utsin
^double [^double r ^double t ^double phase]
(+ 0.5 (* 0.5 (math/sin (* eq/TAU (+ (* r t) phase))))))
Expand All @@ -39,26 +35,26 @@
(defn graph [t]
(let [t (* 0.1 t)]
(fn [x]
(let [tx (+ (tsin 0.05 t -0.1)
(let [tx (+ (eq/phase-sin 0.05 t -0.1)
(utsin 1.15 t (* 0.2 x))
(* 0.1 x))
dtx
(* 1.5 (tsin 0.23 t (* 0.5 x (tsin 1.25 t (+ 0.001 x)))))]
(+ (* (tsin 0.66 (+ tx dtx) 0)
(tsin 1.0
(+ (* 0.011 x)
(* 1.1 (tsin -0.051 t (* 0.05 (- x 1.2))))
(eq/sqr (tsin 0.15 t (tsin 0.0001 t (* 0.01 x)))))
0.0))
(* 0.07 (tsin 0.005 t (+ (* 7 x) 2.9))))))))
(* 1.5 (eq/phase-sin 0.23 t (* 0.5 x (eq/phase-sin 1.25 t (+ 0.001 x)))))]
(+ (* (eq/phase-sin 0.66 (+ tx dtx) 0)
(eq/phase-sin 1.0
(+ (* 0.011 x)
(* 1.1 (eq/phase-sin -0.051 t (* 0.05 (- x 1.2))))
(eq/sqr (eq/phase-sin 0.15 t (eq/phase-sin 0.0001 t (* 0.01 x)))))
0.0))
(* 0.07 (eq/phase-sin 0.005 t (+ (* 7 x) 2.9))))))))

(defn draw [{:keys [t]}]
(q/background 1.0)
(q/color 0.0)
(q/stroke-weight 1.0)
(q/no-fill)
(let [tan-term (+ (* 0.004 t)
(* 1.37 (tsin 0.003 t 0.5)))
(* 1.37 (eq/phase-sin 0.003 t 0.5)))
offset (* 0.15 (tm/clamp (math/tan (* eq/TAU tan-term)) -100 100))]
(doseq [v (range -2 3 1)]
(plot (graph (+ t (* v offset)))
Expand Down

0 comments on commit 9cf56b0

Please sign in to comment.