(ns seni.sketch-1439c
(:require #+clj [seni.render :as r]
#+cljs [seni.render :as r :include-macros true]
[seni.math :as m]
[seni.perlin :as p]
[seni.movement :as mv]
[seni.bezier :as b]
[seni.colour :as c]
[seni.toolbox :as t]))
(defn bezier-stroked-rect
[& {:keys [x y width height col volatility overlap seed]}]
(let [th-width (/ width 3)
th-height (/ height 3)
vol volatility
iterations 10
h-delta (/ height iterations)
h-strip-width (/ height iterations)
half-h-strip-width (/ h-strip-width 2)
v-delta (/ width iterations)
v-strip-width (/ width iterations)
half-v-strip-width (/ v-strip-width 2)
[cr cg cb ca] (c/map-to-byte-range col)
half-alpha (/ ca 2)]
; horizontal strips
(loop [i iterations
prngs (m/lazy-seq-prng-0 seed)]
(when (> i 0)
(let [[rx1 ry1 rx2 ry2 rx3 ry3 rx4 ry4] (take 8 prngs)]
(r/fill-float cr cg cb half-alpha)
(b/render-bezier 10 (+ overlap h-strip-width)
(+ (+ (* rx1 vol) x) (* 0 th-width))
(- (+ (* i h-delta) (* ry1 vol) y) half-h-strip-width)
(+ (+ (* rx2 vol) x) (* 1 th-width))
(- (+ (* i h-delta) (* ry2 vol) y) half-h-strip-width)
(+ (+ (* rx3 vol) x) (* 2 th-width))
(- (+ (* i h-delta) (* ry3 vol) y) half-h-strip-width)
(+ (+ (* rx4 vol) x) (* 3 th-width))
(- (+ (* i h-delta) (* ry4 vol) y) half-h-strip-width))
(recur (dec i) (drop 8 prngs)))))
; vertical strips
(loop [i iterations
prngs (m/lazy-seq-prng-0 (* seed seed))]
(when (> i 0)
(let [[rx1 ry1 rx2 ry2 rx3 ry3 rx4 ry4] (take 8 prngs)]
(r/fill-float cr cg cb half-alpha)
(b/render-bezier 10 (+ overlap v-strip-width)
(- (+ (* i v-delta) (* rx1 vol) x) half-v-strip-width)
(+ (+ (* ry1 vol) y) (* 0 th-height))
(- (+ (* i v-delta) (* rx2 vol) x) half-v-strip-width)
(+ (+ (* ry2 vol) y) (* 1 th-height))
(- (+ (* i v-delta) (* rx3 vol) x) half-v-strip-width)
(+ (+ (* ry3 vol) y) (* 2 th-height))
(- (+ (* i v-delta) (* rx4 vol) x) half-v-strip-width)
(+ (+ (* ry4 vol) y) (* 3 th-height))
)
(recur (dec i) (drop 8 prngs)))))))
(defn draw [state]
(r/background-float 255)
(t/wash 160 160 160 100)
(let [n 10]
(doseq [xp (range 1 (- n 1))
yp (range 1 (- n 1))]
(let [w (/ 1000 n)
h (/ 1000 n)]
(bezier-stroked-rect :x (+ (* w xp) 20) :y (+ (* h yp) 20)
:width (- w 40) :height (- h 40)
:col (c/rgb :r 0.8 :g 0.0 :b 0.0 :alpha 1.0)
:volatility (* 3 (m/distance-2d xp yp (/ n 2) (/ n 2)))
:seed (+ (* xp n) yp)
:overlap 3.0)))))
(r/defsketch sketch-1439c
:title "squares"
:aspect :square
:canvas-width 600
:draw draw)