Skip to content

Commit

Permalink
bubble hatching
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Jan 24, 2025
1 parent 7c58089 commit 481621b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/shimmers/sketches/hatch_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[shimmers.math.geometry :as geometry]
[shimmers.math.vector :as v]
[shimmers.sketch :as sketch :include-macros true]
[thi.ng.geom.circle :as gc]
[thi.ng.geom.core :as g]
[thi.ng.geom.line :as gl]
[thi.ng.geom.rect :as rect]
Expand Down Expand Up @@ -110,10 +111,10 @@
(geometry/rotate-around (gl/line2 pt (g/closest-point line pt))
(g/centroid rect) theta)))))

;; bad random hatch
;; bubble hatching
(fn [cell]
(let [rect (example-rect cell)
points (rp/poisson-disc-sampling rect (dr/random-int 150 300))
points (rp/poisson-disc-sampling rect (dr/random-int 200 300))
rlen (/ (* 8 (g/width rect)) (count points))
center (g/centroid rect)
theta (dr/random-tau)
Expand All @@ -131,7 +132,20 @@
center theta)
(geometry/rotate-around (gl/line2 (v/-polar pt (len) angle1)
(v/+polar pt (len) angle1))
center theta)])))))])
center theta)])))))

(fn [cell]
(let [rect (example-rect cell)
points (rp/poisson-disc-sampling rect (dr/random-int 200 300))
rlen (/ (* 6 (g/width rect)) (count points))
center (g/centroid rect)
theta (dr/random-tau)]
(concat [(geometry/rotate-around-centroid rect theta)]
(for [pt points
:let [d (g/dist pt (g/closest-point rect pt))
len (fn [] (min d (dr/gaussian rlen (/ rlen 8.0))))]
:when (> d (* 0.5 rlen))]
(geometry/rotate-around (gc/circle pt (len)) center theta)))))])

(defn shapes [bounds examples]
(for [[cell example] (map vector (g/subdivide bounds {:num 3})
Expand Down

0 comments on commit 481621b

Please sign in to comment.