Genart

Here's some generative art stuff I've been fucking around with lately.

Circles

The first effort

(ns circles.core
  (:require [quil.core :as q]
            [quil.middleware :as m]))

(def TAU (* q/PI 2))

(defn setup []
  (q/frame-rate 10))

(defn outlineify [im color sz]
  (let [eroded (q/create-graphics sz sz)
        solid (q/create-graphics sz sz)
        output (q/create-graphics sz sz)]
    (q/with-graphics solid
      (apply q/background color))
    (q/with-graphics eroded
      (q/image im 0 0)
      (q/display-filter :erode)
      (q/display-filter :erode))
    (q/with-graphics output
      (q/background 0)
      (q/mask-image solid eroded)
      (q/image solid 0 0))
    (q/mask-image output im)
    output))

(defn make-circ [bars scale]
  (let [sz (int (* scale 500))
        gr (q/create-graphics sz sz)]
    (q/with-graphics gr
      (q/fill 255)
      (q/no-stroke)
      (q/with-translation [(* scale 250) (* scale 250)]
        (doseq [t (range 0 bars)]
          (let [t (q/random TAU) 
                d (q/random 25.0 (* scale 200.0))
                s (* (+ 0.5 (/ d 200.0) scale))]
            (q/with-rotation [t]
              (q/rect 0 d (* 20 s) (* 10 s)))))))
    gr))

(defn draw []
  (q/background (q/random 0 100) (q/random 0 100) (q/random 0 100))
  (doseq [i (range 20)]
    (let [m (- 1. (/ i 20.))
          cx (q/random 100 900)
          cy (q/random 100 900)
          scale (-> (q/random-gaussian)
                    (* 0.3)
                    (+ 1.0)
                    (+ m)
                    (max 0.3)
                    (min 2.0))
          color (map (fn [_] (q/random 0 100)) (range 3))]
      (q/image
        (outlineify
          (make-circ (+ 80 (* (q/random-gaussian) (+ 80 (* m 160)))) scale)
          color
          (int (* scale 500)))
        (- cx (* scale 250))
        (- cy (* scale 250))))))

(defn start []
  (q/defsketch circles
    :title "Circ"
    :size [1000 1000]
    :setup setup
    :draw (fn [] nil)
    :mouse-clicked (fn [] (draw))
    :features [:keep-on-top]
    :middlewake [m/fun-mode]))