1634 Cryst

(meta linear-colour-space: 1)

(define
  title "cryst")

(rect position: [(/ canvas/width 2) (/ canvas/height 2)]
      width: canvas/width
      height: canvas/height
      colour: (col/rgb r: 0 g: 0 b: 0 alpha: 1))

(translate vector: [(/ canvas/width 2) (/ canvas/height 2)])
(rotate angle: 90)

(stroked-bezier-rect position: [0 0]
                     width: 801 ~ (gen/int min: 500 max: canvas/width)
                     height: 613 ~ (gen/int min: 500 max: canvas/height)

                     iterations: 30 ~ (gen/int min: 20 max: 40)
                     overlap: 10 ~ (gen/int min: 0 max: 50)

                     tessellation: 45 ~ (gen/int min: 20 max: 60)

                     stroke-tessellation: 3 ~ (gen/int min: 3 max: 10)
                     stroke-noise: 97 ~ (gen/int min: 80 max: 100)

                     colour: (col/rgb r: 0.072 ~ (gen/scalar max: 0.3)
                                      g: 0.194 ~ (gen/scalar max: 0.3)
                                      b: 0.298 ~ (gen/scalar max: 0.3)
                                      alpha: 0.9)
                     colour-volatility: 121 ~ (gen/int min: 90 max: 130)

                     volatility: 46 ~ (gen/int min: 40 max: 50)
                     seed: 299 ~ (gen/int min: 0 max: 3433))

(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)))