From 762d42c7ccf3d9210829345d98afa930f80bd00b Mon Sep 17 00:00:00 2001 From: Charles Comstock Date: Fri, 25 Oct 2024 14:07:57 -0500 Subject: [PATCH] add projected cilia along the original function --- src/shimmers/sketches/cilia_phase.cljs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/shimmers/sketches/cilia_phase.cljs b/src/shimmers/sketches/cilia_phase.cljs index 93ebae63..72532b91 100644 --- a/src/shimmers/sketches/cilia_phase.cljs +++ b/src/shimmers/sketches/cilia_phase.cljs @@ -4,10 +4,13 @@ [shimmers.common.svg :as csvg :include-macros true] [shimmers.common.ui.controls :as ctrl] [shimmers.common.ui.svg :as usvg] + [shimmers.math.deterministic-random :as dr] [shimmers.math.equations :as eq] [shimmers.sketch :as sketch :include-macros true] + [thi.ng.geom.core :as g] + [thi.ng.geom.line :as gl] [thi.ng.geom.vector :as gv] - [shimmers.math.deterministic-random :as dr])) + [thi.ng.math.core :as tm])) ;; Concept: generate a random phase-shifted function, and then add cilia along ;; it's path. Specifically interested in trying to make another phase shifted @@ -26,14 +29,29 @@ cx' (dr/random)] (fn [x] (math/sin (* eq/TAU (+ (* rx x) cx (* amp (math/cos (* eq/TAU (+ (* rx' x) cx')))))))))) +(defn screen-space [fx x] + (rv x (+ 0.5 (* 0.35 (fx x))))) + (defn base-spline [fx] (for [x (range 0 1 0.0025)] - (rv x (+ 0.5 (* 0.35 (fx x)))))) + (screen-space fx x))) + +;; How to avoid intersecting cilia? +(defn cilias [fx] + (let [spx (spline-fx)] + (for [x (range 0 1 0.005)] + (let [pt (screen-space fx x) + pt' (screen-space fx (+ x 0.0001)) + len (+ 12 (* 8 (spx x))) + offset (tm/normalize (g/rotate (tm/- pt' pt) (* eq/TAU 0.25)) len)] + (gl/line2 (tm/+ pt offset) (tm/- pt offset)))))) (defn shapes [] (let [fx (spline-fx) - spline-pts (base-spline fx)] - [(csvg/path (csvg/segmented-path spline-pts))])) + spline-pts (base-spline fx) + cilia (cilias fx)] + (concat [(csvg/path (csvg/segmented-path spline-pts))] + cilia))) (defn scene [{:keys [scene-id]}] (csvg/svg-timed