1438b

a flower made from Bezier curves

(ns seni.sketch-1438b
  (: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]))

(def width 600)
(def height 600)

(defn setup []
  (r/smooth)
;  (r/no-stroke)
  (r/colour-mode :rgb)
  (r/frame-rate 10)
  ;(r/no-loop)
  (r/stroke 255 0 0)
  (r/stroke-weight 0))

(defn vary
  [x y scale]
  (+ y (* scale (p/perlin x y y))))

(defn wash
  [r g b a]
  (let [variation 200
        line-width 70
        line-segments 5]
    (r/fill-float r g b a)
    (doseq [h (range -20 1020 20)]

      (b/render-bezier line-segments line-width
                       0 (vary 0.10 h variation)
                       333 (vary 333.33 h variation)
                       666 (vary 666.66 h variation)
                       1000 (vary 1000.10 h variation))
      (b/render-bezier line-segments line-width
                       (vary 0.10 h variation) 0
                       (vary 333.33 h variation) 333
                       (vary 666.66 h variation) 666
                       (vary 1000.10 h variation) 1000))))


(defn petal-1
  [ang]
  (r/push-matrix)
  (r/rotate ang)
  (b/render-bezier-bulging 20 50
                           0 0
                           233.33 -100
                           566.66 100
                           800 0)
  (r/pop-matrix))

(defn petal-2
  [ang]
  (r/push-matrix)
  (r/rotate ang)
  (b/render-bezier-bulging 20 50
                           0 0
                           233.33 100
                           566.66 -100
                           800 0)
  (r/pop-matrix))


(defn circ-1
  [petals col scale]
  (r/push-matrix)
  (r/scale scale scale)
  (let [[cr cg cb] (c/map-to-byte-range col)
        strokes petals
        remap (m/remap-fn :from [0 strokes] :to [0 m/two-pi])]
    (doseq [i (range 0 strokes)]
      (r/fill-float cr cg cb 150)
      (petal-2 (remap i))))
  (r/pop-matrix))

(defn circ-2
  [petals col scale]
  (r/push-matrix)
  (r/scale scale scale)
  (let [[cr cg cb] (c/map-to-byte-range col)
        strokes petals
        remap (m/remap-fn :from [0 strokes] :to [0 m/two-pi])]
    (doseq [i (range 0 strokes)]
      (r/fill-float cr cg cb 100)
      (petal-1 (remap i))))
  (r/pop-matrix))

(defn layered-petals
  [petals col scale]
  (circ-1 petals col scale)
  (r/rotate 0.1)
  (circ-2 petals col scale))

(defn flower
  [col posx posy scale]
  (r/push-matrix)

  (r/translate posx posy)
  (r/scale scale scale)
  (let [[c2 c3] (c/analagous col)]
    (layered-petals 23 col 0.6)
    (layered-petals 19 c3 0.5)
    (layered-petals 17 c2 0.3))
  (r/pop-matrix))

(defn draw [state]
  (r/push-matrix)
  (r/scale (/ width 1000) (/ height 1000))

  (r/background-float 255)
  (wash 160 160 160 100)

  (flower (c/rgb :r 0.8 :g 0.3 :b 0.2) 500 500 1.0)

  (r/pop-matrix))

(r/defsketch sketch-1438
  :title "bezier flower"
  :size [width height]
  :setup setup
  :draw draw)