Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created August 19, 2010 17:02
Show Gist options
  • Save seansullivan/538375 to your computer and use it in GitHub Desktop.
Save seansullivan/538375 to your computer and use it in GitHub Desktop.
curvePath = [];
var step = 1 / 100;
var point1, point2, point3;
point1 = {'x': 0, 'y':0};
point2 = {'x':250, 'y':200};
point3 = {'x': 500, 'y':0};
var posX, posY;
//This loops calculates each step of the curve
for (var u = 0; u <= 1; u += step) {
posX = (Math.pow((1-u),2)*point1.x) + (2*(1-u)*u*point2.x) + (Math.pow(u,2)*point3.x);
posY = (Math.pow((1-u),2)*point1.y) + (2*(1-u)*u*point2.y) + (Math.pow(u,2)*point3.y);
curvePath.push({'x':posX, 'y':posY});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment