Created
June 8, 2012 03:46
-
-
Save technomancy/2893426 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sketchbook.prize | |
| (:require [clojure.set :as set]) | |
| (:use [quil.core])) | |
| (declare prize) | |
| (def names ["Chris" "Robin" "Emmett" "Stan" "Jason" "Phil" "Brian"]) | |
| (def uneliminated (atom names)) | |
| (def eliminated (atom {})) | |
| (defn x [n] | |
| (+ 20 (* 80 n))) | |
| (defn draw-names [] | |
| (dotimes [n (count names)] | |
| (let [y (@eliminated (names n) 20)] | |
| (fill (- 255 (* 0.5 (height) (float (/ y (height)))))) | |
| (text (names n) (x n) y)))) | |
| (defn setup [] | |
| (fill 0) | |
| (rect 0 0 (width) (height)) | |
| (fill 255) | |
| (text-font (create-font "Ubuntu Light" 20 true)) | |
| (draw-names)) | |
| (defn drop-names [eliminated] | |
| (zipmap (keys eliminated) (map inc (vals eliminated)))) | |
| (defn winner [name] | |
| (fill 255 0 0) | |
| (text-font (create-font "Ubuntu Light" 40 true)) | |
| (text name (/ (width) 2) (/ (height) 2)) | |
| (fill 255) | |
| (text-font (create-font "Ubuntu Light" 20 true)) | |
| (sketch-stop prize)) | |
| (defn draw [] | |
| (when (zero? (mod (frame-count) 100)) | |
| (when (= (count @uneliminated) 1) | |
| (winner (first @uneliminated))) | |
| (let [chosen (rand-nth @uneliminated)] | |
| (swap! uneliminated #(remove (partial = chosen) %)) | |
| (swap! eliminated assoc chosen 20))) | |
| (draw-names) | |
| (swap! eliminated drop-names)) | |
| (defsketch prize | |
| :setup setup | |
| :draw #'draw | |
| :size [640 480]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment