Skip to content

Commit

Permalink
add lcm/gcd as options for c-multiple in helix sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Apr 29, 2024
1 parent ae6d11f commit 823b339
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/shimmers/math/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@

(comment (map (fn [n] [n (factors n 9)]) (range 1 100)))

;; https://rosettacode.org/wiki/Least_common_multiple#Clojure
(defn gcd [a b]
(if (zero? b)
a
(recur b (mod a b))))

(defn lcm [a b]
(/ (* a b) (gcd a b)))

;; https://en.wikipedia.org/wiki/Lagrange_polynomial
;; https://www.youtube.com/watch?v=4S6G-zenbFM
(defn lagrange-interpolate [points]
Expand Down
6 changes: 5 additions & 1 deletion src/shimmers/sketches/helix.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[shimmers.common.svg :as csvg :include-macros true]
[shimmers.common.ui.controls :as ctrl]
[shimmers.common.ui.debug :as debug]
[shimmers.math.core :as sm]
[shimmers.math.deterministic-random :as dr]
[shimmers.math.equations :as eq]
[shimmers.math.vector :as v]
Expand Down Expand Up @@ -75,7 +76,10 @@
{:n-points 2048
:a (* (dr/weighted {-1 1 1 6}) a)
:b (* (dr/weighted {-1 6 1 1}) b)
:c (* (min a b) (dr/random-int 1 6))
:c (dr/weighted
[[(* (min a b) (dr/random-int 1 6)) 2.0]
[(sm/lcm a b) 1.0]
[(sm/gcd a b) 1.0]])
:a-osc (* (dr/random-sign) (dr/random-int 4))
:b-osc (* (dr/random-sign) (dr/random-int 6))
:c-osc (* (dr/random-sign) (dr/random-int 12))
Expand Down

0 comments on commit 823b339

Please sign in to comment.