1439b

(ns seni.sketch-1439b
  (: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 accumulated-rect
  [& {:keys [x y width height col volatility seed]}]

  (let [half-width (/ width 2)
        half-height (/ height 2)
        passes 10
        prngs (m/lazy-seq-prng-0 seed)
        [cr cg cb ca] (c/map-to-byte-range col)]

    (r/push-matrix)
    ; translate to the centre of the rectangle
    (r/translate (+ x half-width) (+ y half-height))

    (doseq [[rr xr yr] (partition 3 (take (* 3 passes) prngs))]
      (r/push-matrix)

      (r/rotate (* rr 0.02 volatility))
      (r/translate (* xr 5 volatility) (* yr 5 volatility))

      (r/fill-float cr cg cb (/ ca passes))
      (r/rect (- half-width) (- half-height) width height)

      (r/pop-matrix))
    (r/pop-matrix)))

(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)]
       (accumulated-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 (* 1.2 (m/distance-2d xp yp (/ n 2) (/ n 2)))
                         :seed (+ (* xp n) yp))))))

(r/defsketch sketch-1439b
  :title "squares"
  :aspect :square
  :canvas-width 600
  :draw draw)