Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lerp(start, end, bias) = (end * bias + start * (1 - bias));
- function quad_p(sp, cp, ep, t) =
- // Calculates a point for a quadratic bezier curve
- lerp(lerp(sp, cp, t), lerp(cp, ep, t), t);
- /*
- * The first and last point in points[] are used
- * as the start and end points, so give it at least
- * 3 points or it'll probably break. Don't set p.
- */
- function n_p(points=[], p=[], t=0) =
- // Calculates a point for an n-order bezier curve
- (len(p) == 1)
- ? p[0]
- : (len(p) == 0)
- ? n_p(p=[ for(i=[1 : len(points) - 2]) quad_p(points[0], points[i], points[len(points) - 1], t) ], t=t)
- : n_p(p=[ for(i=[0 : len(p) - 2]) lerp(p[i], p[i + 1], t) ], t=t);
- function n_bezier(points, res=.1) = [
- // Generates a n-order bezier curve
- for(t=[0 : res : 1])
- n_p(points, t=t)
- ];
- p1 = [
- [0, 0],
- [50, 500],
- [100, 0],
- [150, -500],
- [250, 500],
- [300, -1000],
- [350, 500],
- [400, 0]
- ];
- for(p=n_bezier(p1, res=.01)) {
- translate(p) sphere(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement