Created
November 9, 2014 12:22
-
-
Save eriksvedang/fe0cba532161b254492d to your computer and use it in GitHub Desktop.
Tailspin variation
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
(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 10)] | |
[r 0]))}) | |
(defn move [dot] | |
(let [[r a] dot] | |
[r (+ a (* r 0.0005))])) | |
(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 5 5) | |
(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