-
-
Save eriksvedang/31e67e4d20ecca89fec0 to your computer and use it in GitHub Desktop.
Tailspin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; By Erik Svedäng, Nov 9 2014 | |
(ns quilinfo.core | |
(:require [quil.core :as q :include-macros true] | |
[quil.middleware :as m])) | |
(defn setup [] | |
(q/frame-rate 30) | |
(q/color-mode :hsb) | |
{:dots (into [] (for [r (range 0 240 20)] | |
[r 0]))}) | |
(defn move [dot] | |
(let [[r a] dot] | |
[r (+ a (* r 0.001))])) | |
(defn update [state] | |
(update-in state [:dots] #(map move %))) | |
(defn dot->coord [[r a]] | |
[(+ (/ (q/width) 2) (* r (q/cos a))) | |
(+ (/ (q/height) 2) (* r (q/sin a)))]) | |
(defn draw [state] | |
(q/background 255) | |
(q/fill 0) | |
(let [dots (:dots state)] | |
(loop [curr (first dots) | |
tail (rest dots) | |
prev (last dots)] | |
(let [[x y] (dot->coord curr)] | |
(q/ellipse x y 10 10) | |
(when prev | |
(let [[x2 y2] (dot->coord prev)] | |
(q/line x y x2 y2)))) | |
(if (seq tail) | |
(recur (first tail) | |
(rest tail) | |
curr))))) | |
(q/defsketch quilinfo | |
:host "quilinfo" | |
:size [500 500] | |
:setup setup | |
:update update | |
:draw draw | |
:middleware [m/fun-mode]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment