Skip to content

Instantly share code, notes, and snippets.

@garyb
Created July 5, 2012 16:25
Show Gist options
  • Save garyb/3054646 to your computer and use it in GitHub Desktop.
Save garyb/3054646 to your computer and use it in GitHub Desktop.
JavaScript Bézier curve
// `a` and `d` are anchor points, `b` and `c` are control points, and `t` is a scalar that specifies the point on the curve you want
var calcBezierValue = function (a, b, c, d, t) {
if (t < 0 || t > 1) return null;
return { x: (t * t * (d.x - a.x) + 3 * (1 - t) * (t * (c.x - a.x) + (1 - t) * (b.x - a.x))) * t + a.x,
y: (t * t * (d.y - a.y) + 3 * (1 - t) * (t * (c.y - a.y) + (1 - t) * (b.y - a.y))) * t + a.y };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment