Skip to content

Instantly share code, notes, and snippets.

@eriksvedang
Created November 9, 2014 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eriksvedang/fe0cba532161b254492d to your computer and use it in GitHub Desktop.
Save eriksvedang/fe0cba532161b254492d to your computer and use it in GitHub Desktop.
Tailspin variation
(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