Skip to content

Commit

Permalink
first pass at a new random shape tiling
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed May 24, 2024
1 parent 0a58e8a commit db1dcaf
Show file tree
Hide file tree
Showing 2 changed files with 65 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 @@ -163,6 +163,7 @@
shimmers.sketches.path-distribution
shimmers.sketches.path-following
shimmers.sketches.path-morph
shimmers.sketches.patterns-shifted
shimmers.sketches.pawns
shimmers.sketches.periapsis
shimmers.sketches.permutations-of-transfiguration
Expand Down
64 changes: 64 additions & 0 deletions src/shimmers/sketches/patterns_shifted.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
(ns shimmers.sketches.patterns-shifted
(:require
[clojure.set :as set]
[shimmers.common.svg :as csvg :include-macros true]
[shimmers.common.ui.controls :as ctrl]
[shimmers.math.deterministic-random :as dr]
[shimmers.math.geometry.triangle :as triangle]
[shimmers.sketch :as sketch :include-macros true]
[shimmers.view.sketch :as view-sketch]
[thi.ng.geom.core :as g]
[thi.ng.geom.vector :as gv]
[thi.ng.math.core :as tm]
[thi.ng.geom.circle :as gc]
[thi.ng.geom.rect :as rect]))

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

(defn random-shape [size]
(dr/weighted
{(triangle/inscribed-equilateral (gv/vec2) size 0) 2
(rect/rect size) 0}))

(defn shapes [size shape n]
(loop [shapes [shape] faces (set (g/edges shape))]
(if (>= (count shapes) n)
shapes
(let [[fp fq] (dr/rand-nth (into [] faces))
mid (tm/mix fp fq 0.5)
structure-face (g/normal (tm/- fq fp))
;; TODO: avoid overlap
shape (g/rotate (random-shape size) (g/heading (tm/- structure-face)))
pos (tm/- mid (tm/* structure-face 0.33))
shape' (g/translate shape pos)]
;; TODO remove connecting edge from new shape
(recur (conj (conj shapes shape') (gc/circle mid 2.0))
(set/union faces (set (g/edges shape'))))))))

(defn scene []
(csvg/svg-timed {:width width
:height height
:stroke "black"
:fill "none"
:stroke-width 0.5}
(shapes (* 0.05 height)
(vary-meta (g/center (random-shape (* 0.05 height))
(rv 0.5 0.5))
assoc :stroke-width 2.0)
64)))

(defn page []
(fn []
[sketch/with-explanation
[:div.canvas-frame [scene]]
[view-sketch/generate :patterns-shifted]
[:div.readable-width]]))

(sketch/definition patterns-shifted
{:created-at "2024-05-23"
:tags #{}
:type :svg}
(ctrl/mount page))

0 comments on commit db1dcaf

Please sign in to comment.