Skip to content

Instantly share code, notes, and snippets.

@JanneSalokoski
Last active January 3, 2017 20:40
Show Gist options
  • Save JanneSalokoski/1b68636e55d85d6633f330938a40a67e to your computer and use it in GitHub Desktop.
Save JanneSalokoski/1b68636e55d85d6633f330938a40a67e to your computer and use it in GitHub Desktop.
var Point = function(x, y)
{
this.x = Number(x);
this.y = Number(y);
this.toString = function()
{
return "(" + this.x + ", " + this.y + ")"
}
}
Point.multiply = (p, n) => new Point(p.x * n, p.y * n);
Point.add = (p1, p2) => new Point(p1.x + p2.x, p1.y + p2.y);
function bezier(t, P0, P1, P2)
{
return Point.add(Point.add(Point.multiply(P0, Math.pow((1-t), 2)), Point.multiply(Point.multiply(P1, t), 2*(1-t))), Point.multiply(P2, Math.pow(t, 2)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment