Skip to content

Commit

Permalink
use a stair step sigmoid to repeat gradient steps of cilia density
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Nov 17, 2024
1 parent 25261f8 commit 7755ecc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/shimmers/math/equations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,17 @@
;; https://stackoverflow.com/a/34576808/34450
(defn flat-smooth [x]
(+ x (- x (* (sqr x) (- 3.0 (* 2.0 x))))))

;; https://math.stackexchange.com/a/2529617/903738
(defn stair-sigmoid
[height hscale hoffset alpha x]
(let [m (- (/ 1 (+ 1 (math/exp (- alpha)))) 0.5)
term (- (* hscale x) hoffset 0.5)
r (- term (math/floor term) 0.5)]
(* height (+ (math/floor term)
(* (/ 1.0 (* 2.0 m))
(- (/ 1.0 (+ 1.0 (math/exp (* -2.0 alpha r)))) 0.5))
1))))

(comment (map (fn [x] (stair-sigmoid 0.1 10.0 0 1 x))
(range 0 1 (/ 1.0 30))))
13 changes: 11 additions & 2 deletions src/shimmers/sketches/cilia_phase.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
:random 0.5
:random-normal 0.66
:stripes 1.5
:sin-stripes 1.0})
:sin-stripes 1.0
:stair-sigmoid 1.33})
proportion
(dr/weighted {6 1.0
5.0 1.0
Expand All @@ -117,6 +118,9 @@
:div-prime div-prime})
:sin-stripes
{:freq (dr/random 0.66 1.33)}
:stair-sigmoid
{:freq (dr/random-int 2 32)
:alpha (dr/random 1.0 3.0)}
{}))))

(defn samples-from-density [{:keys [mode density] :as pts}]
Expand All @@ -142,7 +146,12 @@
(/ (mod (* x mul-prime) div-prime) div-prime)))
:sin-stripes
(for [x (range -0.05 1.05 (/ 1.0 density))]
(eq/unit-sin (* eq/TAU (:freq pts) x)))))
(eq/unit-sin (* eq/TAU (:freq pts) x)))
:stair-sigmoid
(let [freq (:freq pts)
alpha (:alpha pts)]
(for [x (range -0.05 1.05 (/ 1.0 density))]
(eq/stair-sigmoid (/ 1.0 freq) freq 0 alpha x)))))

(defn line-parameters []
(let [n (dr/weighted {(dr/random-int 3 8) 3.0
Expand Down

0 comments on commit 7755ecc

Please sign in to comment.