Skip to content

Instantly share code, notes, and snippets.

@Yaffle
Created August 27, 2015 11:06
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 Yaffle/077779f845d344e339ef to your computer and use it in GitHub Desktop.
Save Yaffle/077779f845d344e339ef to your computer and use it in GitHub Desktop.
var drawArrow = function (context, x1, y1, x2, y2) {
context.lineWidth = 1.25;
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
var a = Math.PI / 8;
var h = 12;
var sa = Math.sin(a);
var ca = Math.cos(a);
context.save();
context.translate(x2, y2);
context.scale(h, h);
context.rotate(-Math.atan2(x2 - x1, y2 - y1));
context.beginPath();
context.moveTo(0, 0);
context.lineTo(+sa, -ca);
context.moveTo(0, 0);
context.lineTo(-sa, -ca);
context.quadraticCurveTo(0, -ca * (2 / 3), sa, -ca);
context.fill();
context.restore();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment