Skip to content

Commit

Permalink
Draw a path between sunflower points instead of dotting along
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Oct 1, 2024
1 parent bb115f3 commit 43dff58
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shimmers/sketches.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
shimmers.sketches.subliminal
shimmers.sketches.substrate
shimmers.sketches.sunflower
shimmers.sketches.sunflower-points
shimmers.sketches.superposition
shimmers.sketches.superposition-mirrored
shimmers.sketches.terrain-grid
Expand Down
42 changes: 42 additions & 0 deletions src/shimmers/sketches/sunflower_points.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(ns shimmers.sketches.sunflower-points
(:require
[clojure.math :as math]
[shimmers.common.svg :as csvg :include-macros true]
[shimmers.common.ui.controls :as ctrl]
[shimmers.common.ui.svg :as usvg]
[shimmers.math.equations :as eq]
[shimmers.math.vector :as v]
[shimmers.sketch :as sketch :include-macros true]
[thi.ng.geom.vector :as gv]
[thi.ng.math.core :as tm]))

(def width 800)
(def height 600)
(defn rv [x y]
(gv/vec2 (* width x) (* height y)))

(defn shapes [{:keys [points alpha]}]
(let [center (rv 0.5 0.5)
radius (* 0.45 (min width height))
exterior (min (int (* alpha (math/sqrt points))) points)
interior (- points exterior)]
(csvg/path (into [[:M center]]
(for [i (range points)
:let [r (if (< i interior) (/ (float i) (inc interior)) 1.0)
theta (* eq/TAU (/ i (eq/sqr tm/PHI)))]]
[:L (v/+polar center (* r radius) theta)])))))

(defn scene [{:keys [scene-id]}]
(csvg/svg-timed {:id scene-id
:width width
:height height
:stroke "black"
:fill "white"
:stroke-width 0.5}
(shapes {:points 256 :alpha 1.0})))

(sketch/definition sunflower-points
{:created-at "2024-09-30"
:tags #{}
:type :svg}
(ctrl/mount (usvg/page sketch-args scene)))

0 comments on commit 43dff58

Please sign in to comment.