Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created January 5, 2015 16:37
Show Gist options
  • Select an option

  • Save drhayes/7749fea12dd634ac03fe to your computer and use it in GitHub Desktop.

Select an option

Save drhayes/7749fea12dd634ac03fe to your computer and use it in GitHub Desktop.
bezier curve functions for ImpactJS.
ig.module(
'game.util.bezier'
)
.defines(function() {
'use strict';
// With the help of: http://www.moshplant.com/direct-or/bezier/math.html
// Code totally stolen from processing.js.
// 0 <= t <= 1
window.bezierPoint = function bezierPoint(a,b,c,d,t) {
return (1-t)*(1-t)*(1-t)*a+3*(1-t)*(1-t)*t*b+3*(1-t)*t*t*c+t*t*t*d;
}
window.bezierTangent = function bezierTangent(a,b,c,d,t) {
return (3*t*t*(-a+3*b-3*c+d)+6*t*(a-2*b+c)+3*(-a+b));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment