Last active
August 26, 2020 01:52
-
-
Save blad/90475fe9ba6be05dacd130e066c00688 to your computer and use it in GitHub Desktop.
Ronin: Drawing a Bézier Curve
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
(defn bezier-line | |
(points color) | |
( | |
(def ts (range 0 1 .001)) | |
; Calculate the coordniates of the bezier curve: | |
(defn bezier-point | |
(t x0 x1 x2) | |
(add x1 | |
(mul | |
(pow | |
(sub 1 t) 2) | |
(sub x0 x1)) | |
(mul | |
(pow t 2) | |
(sub x2 x1)))) | |
; Draw Point on the curve: | |
(defn draw | |
(t0) | |
( | |
(def p0 (:0 points)) | |
(def p1 (:1 points)) | |
(def p2 (:2 points)) | |
(fill | |
(rect | |
(bezier-point t0 p0:x p1:x p2:x) | |
(bezier-point t0 p0:y p1:y p2:y) 1 1) color))) | |
(each ts draw))) | |
; Start Definition of Drawing | |
(clear) | |
(def anchor-a (guide $pos)) | |
(def control (guide $pos)) | |
(def anchor-b (guide $pos)) | |
(bezier-line (anchor-a control anchor-b) "red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment