Skip to content

Instantly share code, notes, and snippets.

@melklein
Created July 8, 2016 18:56
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 melklein/88498da3706c277915356b6ee6652024 to your computer and use it in GitHub Desktop.
Save melklein/88498da3706c277915356b6ee6652024 to your computer and use it in GitHub Desktop.
(ns fun-mode-sketch
(:require [quil.core :as q]
[quil.middleware :as m]))
(def win-width 400)
(def win-height 200)
(def bar-width 1)
(def bar-height 10)
(def bar-count (/ win-width bar-width))
(def grow-bar (partial + bar-height))
(defn setup []
(q/frame-rate 60)
{:bars (vec (repeat bar-count 0))})
(defn update [state]
(let [bar-to-grow (int (rand bar-count))
new-bars (update-in (:bars state) [bar-to-grow] grow-bar)]
(assoc state :bars new-bars)))
(defn draw [state]
(q/background 255)
(q/fill 0)
(doall
(map-indexed
(fn [i height]
(q/rect (* i bar-width) (- win-height height) bar-width height))
(:bars state))))
(q/defsketch example
:size [win-width win-height]
:setup setup
:draw draw
:update update
:middleware [m/fun-mode])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment