Skip to content

Instantly share code, notes, and snippets.

@tyt2y3 tyt2y3/bezier2.as
Last active Dec 17, 2015

Embed
What would you like to do?
the simplest snippet for evaluating quadratic bezier curves. only integer computation is involved.
function bezier2(ax, ay, bx, by, cx, cy) {
var minlength = 20;
var dist = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2)) + Math.sqrt(Math.pow(bx - cx, 2) + Math.pow(by - cy, 2));
var steps = dist / minlength;
moveTo(ax, ay);
for (var i=0; i<steps; i++) {
var x = getstep(getstep(ax, bx, i, steps), getstep(bx, cx, i, steps), i, steps);
var y = getstep(getstep(ay, by, i, steps), getstep(by, cy, i, steps), i, steps);
lineTo(x, y);
}
lineTo(cx, cy);
}
function getstep(x1, x2, stepcount, numofsteps) {
return ((numofsteps - stepcount) * x1 + stepcount * x2) / numofsteps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.