Skip to content

Commit

Permalink
use minkowski? as another density function
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Nov 24, 2024
1 parent 23fb088 commit 3a0a00c
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 @@ -210,3 +210,17 @@

(comment (map (fn [x] (stair-sigmoid 0.1 10.0 0 1 x))
(range 0 1 (/ 1.0 30))))

;; https://en.wikipedia.org/wiki/Minkowski%27s_question-mark_function
;; https://rosettacode.org/wiki/Minkowski_question-mark_function#Julia
(defn minkowski? [^double x]
(loop [p (mod x 1.0) q (- 1.0 x) y (quot x 1.0) d 0.5]
(if (> (+ y d) y)
(if (< p q)
(recur p (- q p) y (/ d 2.0))
(recur (- p q) q (+ y d) (/ d 2.0)))
y)))

(comment
(for [x (range 0 1 0.02)]
[x (minkowski? x)]))
13 changes: 11 additions & 2 deletions src/shimmers/sketches/cilia_phase.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
:random-normal 0.66
:stripes 1.33
:sin-stripes 1.0
:stair-sigmoid 2.0})
:stair-sigmoid 2.0
:minkowski 1.33})
proportion
(dr/weighted {6 1.0
5.0 1.0
Expand Down Expand Up @@ -127,6 +128,9 @@
:alpha (dr/random 1.0 3.0)
:rate (* 2.5 (dr/happensity 0.4))
:amp (dr/weighted {0.05 1.0 0.075 1.0 0.025 1.0 0.1 0.5})}
:minkowski
{:amp (dr/random 0.05 0.25)
:rate (dr/random 1.0 4.0)}
{}))))

(defn samples-from-density [{:keys [mode density] :as pts}]
Expand Down Expand Up @@ -157,7 +161,12 @@
(let [{:keys [freq alpha rate amp]} pts]
(for [x (range -0.05 1.05 (/ 1.0 density))]
(eq/stair-sigmoid (/ 1.0 freq) freq 0 alpha
(+ x (* amp (eq/sin-tau (* rate x)))))))))
(+ x (* amp (eq/sin-tau (* rate x)))))))
:minkowski
(let [{:keys [amp rate]} pts]
(for [x (range -0.05 1.05 (/ 1.0 (* 1.2 density)))]
(+ (eq/minkowski? x)
(* amp (eq/sin-tau (+ (* rate x)))))))))

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

0 comments on commit 3a0a00c

Please sign in to comment.