1531 Four Squares

(meta linear-colour-space: 1)

(wash colour: (col/rgb r: 0.827 g: 0.827 b: 0.827 alpha: 0.4)
      seed: 88)

(define
  base-colour (col/rgb r: 0.9 g: 0.0 b: 0.0 alpha: 1.0)
  border 30
  square-size (/ (- canvas/width (* 3 border)) 2)
  square-radius (/ square-size 2)
  square-pos-min (+ border square-radius)
  square-pos-max (- canvas/width (+ border square-radius)))

(rect position: [square-pos-min square-pos-max]
      width: square-size height: square-size
      colour: base-colour)

(accumulated-rect position: [square-pos-max square-pos-max]
                  width: square-size height: square-size
                  colour: base-colour
                  volatility: 1.5
                  passes: 50)

(stroked-bezier-rect position: [square-pos-min square-pos-min]
                     width: square-size
                     height: square-size
                     colour: base-colour
                     colour-volatility: 12
                     tessellation: 1
                     volatility: 2.0
                     overlap: 3.0
                     stroke-tessellation: 12
                     stroke-noise: 2
                     iterations: 10
                     brush: brush/flat
                     brush-subtype: 0
                     seed: 33)

(stroked-bezier-rect position: [square-pos-max square-pos-min]
                     width: square-size
                     height: square-size
                     colour: base-colour
                     colour-volatility: 20
                     volatility: 0.5
                     overlap: 2.5
                     iterations: 79)

(fn (accumulated-rect position: [0 0]
                      width: 10
                      height: 10
                      colour: (col/rgb r: 0.0 g: 1.0 b: 0.0 alpha: 0.5)
                      volatility: 0
                      passes: 1
                      seed: 33)
  (define
    alpha (col/alpha from: colour)
    pass-colour (col/set-alpha from: colour value: (/ alpha passes))
    rng (prng/build min: -1 max: 1 seed: seed))

  (on-matrix-stack
    (translate vector: position)
    (loop (i to: passes)
      (define [rr xr yr] (prng/values num: 3 from: rng))
      (on-matrix-stack
        (rotate angle: (math/radians->degrees angle: (* rr 0.02 volatility)))
        (rect position: [(* xr 5 volatility) (* yr 5 volatility)]
              width: width
              height: height
              colour: pass-colour)))))

(fn (stroked-bezier-rect position: [100 100]
                         width: 80
                         height: 600
                         volatility: 30
                         overlap: 0
                         iterations: 10
                         seed: 0

                         tessellation: 15
                         stroke-tessellation: 10
                         stroke-noise: 25

                         colour: (col/rgb r: 0.0 g: 1.0 b: 0.0 alpha: 0.5)
                         colour-volatility: 0

                         brush: brush/flat
                         brush-subtype: 1)
  (define
    [x y] position

    x-start (- x (/ width 2.0))
    y-start (- y (/ height 2.0))

    th-width (/ width 3.0)
    th-height (/ height 3.0)

    vol volatility

    cc-lab(colour.col/convert format: LAB)
    half-alpha-col (col/set-alpha from: cc-lab value: (* 0.5 (cc-lab.col/alpha)))

    prng (prng/build seed min: -1 max: 1)

    sum-thickness (+ height (* (- iterations 1.0) overlap))
    stroke-thickness (/ sum-thickness iterations)
    stroke-half-thickness (/ stroke-thickness 2.0)
    stroke-offset-factor (/ (- height overlap) iterations)

    v-sum-thickness (+ width (* (- iterations 1.0) overlap))
    v-stroke-thickness (/ v-sum-thickness iterations)
    v-stroke-half-thickness (/ v-stroke-thickness 2.0)
    v-stroke-offset-factor (/ (- width overlap) iterations))

  ;; horizontal strokes
  (loop (i to: iterations)
    (define
      h (+ y-start stroke-half-thickness (* i stroke-offset-factor))
      coords [[(+ (* (prng.prng/value) vol) x-start (* 0 th-width))
               (+ h (* (prng.prng/value) vol))]
              [(+ (* (prng.prng/value) vol) x-start (* 1 th-width))
               (+ h (* (prng.prng/value) vol))]
              [(+ (* (prng.prng/value) vol) x-start (* 2 th-width))
               (+ h (* (prng.prng/value) vol))]
              [(+ (* (prng.prng/value) vol) x-start (* 3 th-width))
               (+ h (* (prng.prng/value) vol))]])
    (stroked-bezier tessellation
                    coords
                    stroke-tessellation
                    stroke-noise
                    stroke-line-width-start: stroke-thickness
                    stroke-line-width-end: stroke-thickness
                    colour: half-alpha-col
                    colour-volatility
                    seed: (prng.prng/value)
                    brush
                    brush-subtype))

  ;; vertical strokes
  (loop (i to: iterations)
    (define
      v (+ x-start v-stroke-half-thickness (* i v-stroke-offset-factor))
      coords [[(+ v (* (prng.prng/value) vol))
               (+ (* (prng.prng/value) vol) y-start (* 0 th-height))]
              [(+ v (* (prng.prng/value) vol))
               (+ (* (prng.prng/value) vol) y-start (* 1 th-height))]
              [(+ v (* (prng.prng/value) vol))
               (+ (* (prng.prng/value) vol) y-start (* 2 th-height))]
              [(+ v (* (prng.prng/value) vol))
               (+ (* (prng.prng/value) vol) y-start (* 3 th-height))]])
    (stroked-bezier tessellation
                    coords
                    stroke-tessellation
                    stroke-noise
                    stroke-line-width-start: stroke-thickness
                    stroke-line-width-end: stroke-thickness
                    colour: half-alpha-col
                    colour-volatility
                    seed: (prng.prng/value)
                    brush
                    brush-subtype)))

(fn (wash vol: 200
          line-width: 70
          line-segments: 5
          colour: (col/rgb r: 0.627 g: 0.627 b: 0.627 alpha: 0.4)
          seed: 272)
  (define
    w/3 (/ canvas/width 3)
    h/3 (/ canvas/height 3))
  (loop (d from: -20 to: 1020 inc: 20)
    (bezier tessellation: line-segments
            line-width: line-width
            coords: [[0            (wash-n x: 0            d: d seed: seed vol: vol)]
                     [w/3          (wash-n x: w/3          d: d seed: seed vol: vol)]
                     [(* w/3 2)    (wash-n x: (* w/3 2)    d: d seed: seed vol: vol)]
                     [canvas/width (wash-n x: canvas/width d: d seed: seed vol: vol)]]
            colour: colour)

    (bezier tessellation: line-segments
            line-width: line-width
            coords: [[(wash-n x: 0             d: d seed: seed vol: vol) 0]
                     [(wash-n x: h/3           d: d seed: seed vol: vol) h/3]
                     [(wash-n x: (* h/3 2)     d: d seed: seed vol: vol) (* h/3 2)]
                     [(wash-n x: canvas/height d: d seed: seed vol: vol) canvas/height]]
            colour: colour)))

(fn (wash-n x: 0 d: 0 seed: 0 vol: 1)
  (+ d (* vol (prng/perlin x: x y: d z: seed))))