Created
July 8, 2016 18:56
-
-
Save melklein/88498da3706c277915356b6ee6652024 to your computer and use it in GitHub Desktop.
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 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