Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmpvar/e3c4097280fa663d85f9 to your computer and use it in GitHub Desktop.
Save tmpvar/e3c4097280fa663d85f9 to your computer and use it in GitHub Desktop.
polygon snippets
var roundCorner = function(p, c, n) {
var v = Vec2(1, 0);
var oangle = v.angleTo(p.subtract(c, true))
var ae1 = v.angleTo(c.subtract(p, true));
var ae2 = v.angleTo(n.subtract(c, true))
var range = (ae2 > ae1) ? ae2-ae1 : TAU-(ae1 - ae2);
oangle += TAU/4
if (delta < 0) {
range = TAU - range;
if (range > TAU/2) {
return;
}
}
var steps = 10 + Math.floor(delta*.025);
var stepSize = range / steps;
if (delta < 0) {
range /= 2;
stepSize = -stepSize;
}
var b = Vec2(delta, 0).rotate(oangle);
for (var i = 0; i<steps; i++) {
collect(c.add(b.rotate(stepSize), true), c, 'green')
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment