Last active
April 18, 2019 22:16
-
-
Save gferreira/9625334 to your computer and use it in GitHub Desktop.
translation along a path
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
'''draw a range of shapes along a bezier segment''' | |
# converted from: | |
# http://13thparallel.com/archive/bezier-curves/ | |
def B1(t): return t*t*t | |
def B2(t): return 3*t*t*(1-t) | |
def B3(t): return 3*t*(1-t)*(1-t) | |
def B4(t): return (1-t)*(1-t)*(1-t) | |
def getPoint(t, p1, p2, p3, p4): | |
x1, y1 = p1 | |
x2, y2 = p2 | |
x3, y3 = p3 | |
x4, y4 = p4 | |
x = x1*B1(t) + x2*B2(t) + x3*B3(t) + x4*B4(t) | |
y = y1*B1(t) + y2*B2(t) + y3*B3(t) + y4*B4(t) | |
return x, y | |
size(200, 200) | |
fill(None) | |
stroke(1, 0, 0) | |
strokeWidth(1) | |
B = BezierPath() | |
B.moveTo((60, 26)) | |
B.curveTo((-34, 186), (210, 222), (158, 38)) | |
drawPath(B) | |
p1, p4 = B.onCurvePoints | |
p2, p3 = B.offCurvePoints | |
Variable([ | |
dict(name='n', ui='Slider', args=dict(value=80, minValue=2, maxValue=160)), | |
dict(name='a', ui='Slider', args=dict(value=45.0, minValue=0.0, maxValue=180.0)), | |
dict(name='f', ui='Slider', args=dict(value=0.5, minValue=0.01, maxValue=1.0)), | |
], | |
globals()) | |
n = int(n) | |
r = 10 | |
for i in range(n+1): | |
t = i * (1.0 / n) | |
x, y = getPoint(t, p1, p2, p3, p4) | |
save() | |
translate(x, y) | |
rotate(a) | |
oval(-r, -r*f, r*2, r*f*2) | |
restore() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment