From 549c54b00d34983dcdddc57a458d87789cd137aa Mon Sep 17 00:00:00 2001 From: arne Date: Thu, 26 Apr 2018 08:18:18 +0200 Subject: [PATCH] Aphorism two --- src/aphorisms/two.clj | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/aphorisms/two.clj diff --git a/src/aphorisms/two.clj b/src/aphorisms/two.clj new file mode 100644 index 0000000..2bc6144 --- /dev/null +++ b/src/aphorisms/two.clj @@ -0,0 +1,50 @@ +(ns aphorisms.two + (:require [quil.core :as q] + [quil.middleware :as m])) + +(def radius 75) +(def color-progress 1.7) + +(defn settings [] + (q/pixel-density (q/display-density))) + +(defn setup [] + ; Set frame rate to 30 frames per second. + (q/frame-rate 30) + ; Set color mode to HSB (HSV) instead of default RGB. + (q/color-mode :hsb) + ; setup function returns initial state. It contains + ; circle color and position. + {:color 0}) + +(defn update-state [state] + ; Update sketch state by changing circle color and position. + (assoc state :color (mod (+ (:color state) color-progress) 255))) + +(defn draw-state [state] + (q/background 240) + (q/no-fill) + (q/with-translation [(/ (q/width) 2) + (/ (q/height) 2)] + (dotimes [i 18] + (let [color (- (:color state) (* i color-progress)) + angle (- (/ (* q/TWO-PI (q/frame-count)) 60) (* i (/ q/PI 6))) + x (* radius (q/sin angle)) + y (* radius (q/cos angle))] + (q/stroke color 255 255) + (q/line (* 0.6 x) (* 0.6 y) x y))))) + +(q/defsketch aphorism-two + :title "Two" + :size [500 500] + :settings settings + ; setup function called only once, during sketch initialization. + :setup setup + ; update-state is called on each iteration before draw-state. + :update update-state + :draw draw-state + :features [:keep-on-top] + ; This sketch uses functional-mode middleware. + ; Check quil wiki for more info about middlewares and particularly + ; fun-mode. + :middleware [m/fun-mode m/pause-on-error])