Created
November 27, 2018 22:13
-
-
Save ooesili/1bbf1502a9da578077078426b0693e70 to your computer and use it in GitHub Desktop.
Circles
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 quils.circles.core | |
(:require [quil.core :as q] | |
[quils.util :refer :all])) | |
(def TAU (* 2 q/PI)) | |
(def max-depth 4) | |
(defn setup [] | |
(q/frame-rate 1) | |
(q/color-mode :hsb) | |
{}) | |
(defn draw-circles [depth] | |
(let [radius 10 | |
diameter (* 2 radius) | |
angle-step (/ TAU 6)] | |
(q/ellipse 0 0 diameter diameter) | |
(q/ellipse 0 0 (* 2 diameter) (* 2 diameter)) | |
(when-not (zero? depth) | |
(doseq [i (range 6)] | |
(with-matrix | |
(q/rotate (* i angle-step)) | |
(q/translate 0 radius) | |
(draw-circles (dec depth))))))) | |
(defn draw-state [state] | |
(q/background 0 0 0) | |
(q/no-fill) | |
(q/stroke 64 255 255 8) | |
(q/stroke-weight 0.5) | |
(with-matrix | |
(q/translate (/ (q/width) 2) (/ (q/height) 2)) | |
(q/scale (/ (q/width) 100) (/ (q/height) 100)) | |
(draw-circles max-depth))) |
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 quils.circles.sketch | |
(:require [quil.core :as q] | |
[quil.middleware :as m] | |
[quils.circles.core :as core])) | |
(q/defsketch circles | |
:title "Circles" | |
:size [800 800] | |
:setup core/setup | |
:update identity | |
:draw core/draw-state | |
:features [] | |
:middleware [m/fun-mode]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment