Created
June 29, 2020 08:01
-
-
Save nariakiiwatani/2a6f8b38e56e93289b9d2b3d3b7e096b 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 fix-distance | |
[base desire distance] | |
(let [angle (vec2/angle (vec2/- desire base))] | |
(vec2/rotate base angle (vec2/+ base [distance 0])))) | |
(def limb | |
^(assoc (meta line) :handles { | |
:draw (get (get (meta line) :handles) :draw) | |
:drag (fn [{:id id :pos p :delta-pos dp :params [from to]}] | |
(let [length 100] | |
(case id | |
:path [(vec2/+ from dp) (vec2/+ to dp)] | |
:from [p (fix-distance p to length)] | |
:to [(fix-distance p from length) p]))) | |
}) line) | |
(defvar l0 [0 0]) | |
(defvar l1 [-16.5 -75.6875]) | |
(defvar l2 [36.63257718067095 -42.350391838852715]) | |
(defvar l3 [83.5 -130.6875]) | |
(defvar l4 [108.5 22.3125]) | |
(defvar l5 [172.14061922824524 -54.82291070251394]) | |
(def l1 (fix-distance l0 l1 100)) | |
(def l2 (fix-distance l1 l2 80)) | |
(def l3 (fix-distance l2 l3 60)) | |
(def l4 (fix-distance l3 l4 40)) | |
(def l5 (fix-distance l4 l5 20)) | |
:start-sketch | |
(style (stroke "skyblue" 10) | |
(limb (const l0) l1) | |
(limb l1 l2) | |
(limb l2 l3) | |
(limb l3 l4) | |
(limb l4 l5) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment