Draft

Embedding Quil sketches

Draft of 2016.08.17

May include: visualizationprogramming&c.

I have some interactive simulations to share with you, but they’re written in Clojure (and ClojureScript, now). I’m exploring some tech I’ve seen but not worked extensively: the Quil library, which wraps Processing.js.

This is just an experiment. If you click the “Start!” button below, a simple script will (one hopes) start drawing a very colorful coffee stain on your screen, which will look (after a while) something like this:

Here’s some source code, in case you’re wondering:

(ns wheelie.core
  (:require [quil.core :as q :include-macros true]
            [quil.middleware :as m]))

(defn setup []
  (q/frame-rate 50)
  (q/color-mode :hsb)
  {:color 0
   :angle 0
   :diameter 100})


(defn update-state [state]
  {:color (mod (+ (:color state) (/ (rand) 5)) 255)
   :angle (+ (:angle state) (/ (rand) 100))
   :diameter (min 200 (max 10 (+ (:diameter state) (rand-int 5) -2)))
   })


(defn draw-state [state]
  ;(q/background 120)
  (q/no-stroke)
  (q/fill (:color state) 255 255 2)
  (let [angle (:angle state)
        d     (:diameter state)
        x     (* 150 (q/cos angle))
        y     (* 150 (q/sin angle))]
    (q/with-translation [(/ (q/width) 2)
                         (/ (q/height) 2)]
      (q/ellipse x y d d))))


(q/defsketch wheelie
  :host "wheelie"
  :features [:no-start]
  :size [500 500]
  :setup setup
  :update update-state
  :draw draw-state
  :middleware [m/fun-mode])