Skip to content

Instantly share code, notes, and snippets.

@shspage
Last active December 17, 2020 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shspage/7434c54000589e3088f4b6b25669a00c to your computer and use it in GitHub Desktop.
Save shspage/7434c54000589e3088f4b6b25669a00c to your computer and use it in GitHub Desktop.
gilsp( https://github.com/baku89/glisp ) 用スクリプトです。多角形をUIとして使う習作
; controllers
(def G0 (ngon [1 1.8125] 137 11))
(def G1 (ngon [3 0.8125] 106 7))
(def G2 (ngon [9 -4.1875] 74 8))
(def G3 (ngon [8 -1.1875] 46 5))
; coordinates of the nth vertex
(defn fv [s n] (nth s (inc n)))
; number of vertices
(defn fc [s] (dec (count s)))
; center of the ngon
(defn fo [s] (vec2/scale
(apply vec2/+ (drop 1 s)) (/ 1 (fc s))))
; radius of the ngon
(defn fr [s] (vec2/dist (fo s) (fv s 0)))
; angle from the center of the nth vertex
(defn ft [s n]
(vec2/angle (vec2/- (fv s n) (fo s))))
; length of one side of the ngon
(defn fd [s] (vec2/dist (fv s 0) (fv s 1)))
:start-sketch
(background "#fff")
(style (stroke "#888" 8)
(for [G [G0 G1 G2 G3]]
(let [r (/ (fd G) 3)]
(for [n (range (fc G))]
(circle (fv G n) r)
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment