Last active
October 4, 2018 21:09
-
-
Save chris-olszewski/4c54248ba058fe73be5c3ece6dc300bc to your computer and use it in GitHub Desktop.
Print 10
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 quil-site.examples.ten-print | |
(:require [quil.core :as q :include-macros true] | |
[quil.middleware :as m] | |
)) | |
(def start-scale 10) | |
(def ratio 0.9) | |
(def threshold 2) | |
(def initial-setup | |
{:x 0 | |
:y 0 | |
:scale-x start-scale | |
:scale-y start-scale}) | |
(defn update-state [{:keys [x y scale-x scale-y] :as state}] | |
(let [is-newline (>= x (q/width)) | |
is-restart (< scale-y threshold) | |
new-scale-x (if is-restart (* scale-x ratio) scale-x) | |
new-scale-y (if is-restart | |
new-scale-x | |
(if is-newline (* scale-y ratio) scale-y)) | |
new-x (if is-newline 0 (+ x scale-x)) | |
new-y (if (zero? new-x) (+ y scale-y) y)] | |
{:x new-x | |
:y (if (>= new-y (q/height)) new-y new-y) | |
:scale-x new-scale-x | |
:scale-y new-scale-y})) | |
(defn draw-state [{:keys [x y scale-x scale-y once] :as state}] | |
(q/stroke (rand-int 255) (rand-int 255) 255) | |
(if (> (rand) 0.5) | |
(q/line x y (+ x scale-x) (+ y scale-y)) | |
(q/line x (+ y scale-y) (+ x scale-x) y))) | |
(defn draw-sk [] | |
(q/background 0) | |
(q/color-mode :hsb) | |
(loop [state initial-setup] | |
(when (< (:y state) (q/height)) | |
(draw-state state) | |
(recur (update-state state))))) | |
(q/defsketch ten-print | |
:host "host" | |
:size [500 500] | |
:draw draw-sk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment