Created
August 27, 2015 11:06
-
-
Save Yaffle/077779f845d344e339ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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