Last active
December 19, 2017 23:09
-
-
Save tsulej/1a0c95de454f84dbb54d50d9095bab51 to your computer and use it in GitHub Desktop.
Remake for clojure2d - https://github.com/jedahan/twelve-plus-eight
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 twelve-plus-eight | |
(:require [clojure2d.core :refer :all] | |
[clojure2d.math :as m] | |
[clojure2d.math.vector :as v])) | |
(def ^:const max-lines 40) | |
(def ^:const num-points 60) | |
(def thetas (range 0 m/TWO_PI (/ m/PI 60.0))) | |
(defn squircle | |
"Calculate rounded square point for given angle and curvature" | |
[theta curvature] | |
(let [s (m/sin theta) | |
c (m/cos theta)] | |
(v/vec2 (* (m/pow (m/abs c) curvature) (m/signum c)) | |
(* (m/pow (m/abs s) curvature) (m/signum s))))) | |
(defn draw | |
"Draw" | |
[canvas window _ [padding-ratio num-lines]] | |
(-> canvas | |
(set-background 220 220 110) | |
(set-color :black) | |
(set-stroke 2.0)) | |
(let [padding-amount (* padding-ratio (width canvas))] | |
(dotimes [i num-lines] | |
(let [radius-ratio (m/norm i 0 (dec num-lines)) | |
radius (+ (* (width canvas) radius-ratio (- 0.5 (* 2.0 padding-ratio))) padding-amount) | |
squircle-path (map #(v/mult (squircle %1 (- 1.0 radius-ratio)) radius) thetas)] | |
(-> canvas | |
(push-matrix) | |
(translate (/ (width canvas) 2) (/ (height canvas) 2)) | |
(path squircle-path true) | |
(pop-matrix))))) | |
[(m/norm (mouse-y window) -1 (height canvas) 0.01 0.49) | |
(m/norm (mouse-x window) -1 (width canvas) 2.0 max-lines)]) | |
(def window (show-window {:canvas (make-canvas 900 900) | |
:draw-fn draw | |
:draw-state [0.1 11]})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment