-
-
Save eliheuer/7f5ff1613b8ae36bfb177b894e299870 to your computer and use it in GitHub Desktop.
Bezier demo for DrawBot
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
def lerp(v1, v2, t): | |
return v1 + t * (v2 - v1) | |
def lerpPoint(p1, p2, t): | |
return lerp(p1[0], p2[0], t), lerp(p1[1], p2[1], t) | |
def circle(p, r): | |
x, y = p | |
d = r * 2 | |
oval(x - r, y - r, d, d) | |
Variable([dict(name="t", ui="Slider", args=dict(minValue=0, value=0, maxValue=1))], globals()) | |
p1 = (100, 100) | |
p2 = (256, 662) | |
p3 = (686, 620) | |
p4 = (880, 184) | |
m1 = lerpPoint(p1, p2, t) | |
m2 = lerpPoint(p2, p3, t) | |
m3 = lerpPoint(p3, p4, t) | |
mm1 = lerpPoint(m1, m2, t) | |
mm2 = lerpPoint(m2, m3, t) | |
bp = lerpPoint(mm1, mm2, t) | |
stroke(0) | |
for p in [p1, p2, p3, p4]: | |
circle(p, 4) | |
line(p1, p2) | |
line(p2, p3) | |
line(p3, p4) | |
line(m1, m2) | |
line(m2, m3) | |
line(mm1, mm2) | |
circle(bp, 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment