Created
June 27, 2020 16:07
-
-
Save nariakiiwatani/db7f85f12bf91408e6ab0e78d9e5f296 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
| (defn hand | |
| {:params [{:label "length" :type "number"} | |
| {:label "rot" :type "angle"}] | |
| :handles {:draw (fn [{:params [l r]}] | |
| [{:id "edge" :type "point" :pos (vec2/* [(cos r) (sin r)] [l l])}]) | |
| :drag (fn [{:id id :pos p :params [l r]}] [(vec2/dist [0 0] p) (vec2/angle p)]) | |
| } | |
| } | |
| [l r] | |
| (transform (rotate r) | |
| (line [0 0] [l 0]))) | |
| (defn seconds [t] t) | |
| (defn minutes [t] (* (seconds t) 60)) | |
| (defn hours [t] (* (minutes t) 60)) | |
| (defn to-seconds | |
| {:inverse (fn [ret] [ret])} | |
| [t] t) | |
| (defn to-minutes | |
| {:inverse (fn [ret] [(* ret (seconds 60))])} | |
| [t] (/ (to-seconds t) 60)) | |
| (defn to-hours | |
| {:inverse (fn [ret] [(* ret (minutes 60))])} | |
| [t] (/ (to-minutes t) 60)) | |
| (deftime t 20012.572443461486 :duration 86400) | |
| (defvar speed 200) | |
| (def t (* t speed)) | |
| (defvar size 100) | |
| (defn linear-map | |
| {:inverse (fn [ret [from to value]] [to from value])} | |
| [from to value] | |
| (lerp (second to) (first to) (/ (- value (first from)) (- (second from) (first from)))) | |
| ) | |
| (defn to-clock-angle | |
| [max value] | |
| (linear-map [0 max] [0 (turn 1)] (mod value max))) | |
| (transform (rotate (- HALF_PI)) | |
| (style (stroke "salmon" 10) (circle [0 0] size)) | |
| (style (stroke "black" 10) | |
| (hand (const 50) (to-clock-angle 12 (to-hours t)))) | |
| (style (stroke "black" 5) | |
| (hand (const 100) (to-clock-angle 60 (to-minutes t)))) | |
| (style (stroke "black" 1) | |
| (hand (const 100) (to-clock-angle 60 (to-seconds t)))) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment