Skip to content

Instantly share code, notes, and snippets.

@peterszerzo
Created December 21, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterszerzo/4e35067a015b410d8021e70c03d2def0 to your computer and use it in GitHub Desktop.
Save peterszerzo/4e35067a015b410d8021e70c03d2def0 to your computer and use it in GitHub Desktop.
Abstract floor plan animation in http://www.quil.info/
(ns floorplan.core
(:require [quil.core :as q]
[quil.middleware :as m]))
(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
:angle 0
:time q/millis}
)
(defn update-state [state]
; Update sketch state by changing circle color and position.
{ :color (mod (+ (:color state) 0.7) 255)
:angle (+ (:angle state) 0.1)
:time (q/millis)
})
(def PI 3.14159)
(defn abstract-line [x1 y1 dx dy time]
(doseq
[ i (range 0 1 0.0125)
]
(let
[ x (q/lerp x1 (+ x1 dx) i)
y (q/lerp y1 (+ y1 dy) i)
h (- (* 40 (q/noise (+ (* i 30) (* 0.0006 time)))) 3)
]
(q/push-matrix)
(q/translate x y)
(q/rotate
(if (not= dx 0) (* PI 0.125) (* PI -0.375)))
(q/line
[ 0 (- (/ h 2)) ]
[ 0 (/ h 2) ])
(q/pop-matrix))))
(defn draw-state [state]
(q/background 255)
(q/no-stroke)
(q/fill 0 255 0)
;(q/ellipse 300 200 160 160)
(q/no-fill)
(let
[ hue (+ (mod (* 0.01 (:time state)) 5) 10)
]
(q/stroke hue 255 0))
(q/stroke-weight 3)
(q/stroke-cap :square)
(abstract-line -300 300 500 0 (:time state))
(abstract-line 200 200 500 0 (:time state))
(abstract-line -50 400 500 0 (:time state))
(abstract-line 350 200 0 500 (:time state))
(abstract-line 50 100 500 0 (:time state))
(abstract-line 200 0 0 500 (:time state)))
(q/defsketch sketch-2019-12-13
:title "You spin my circle right round"
:size [504 504]
:setup setup
:update update-state
:draw draw-state
:features [:keep-on-top]
:middleware [m/fun-mode])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment