Created
December 29, 2024 19:40
-
-
Save ZachSaucier/f6886eed8db2e3de4ba1ec0b61da7569 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function draw_arrow(context, x, y, angle, magnitude) { | |
const head_length = 10; | |
const dx = Math.cos(angle) * magnitude; | |
const dy = Math.sin(angle) * magnitude; | |
const end_x = x + dx; | |
const end_y = y + dy; | |
context.beginPath(); | |
context.moveTo(x, y); | |
context.lineTo(end_x, end_y); | |
context.lineTo(end_x - head_length * Math.cos(angle - Math.PI / 6), end_y - head_length * Math.sin(angle - Math.PI / 6)); | |
context.moveTo(end_x, end_y); | |
context.lineTo(end_x - head_length * Math.cos(angle + Math.PI / 6), end_y - head_length * Math.sin(angle + Math.PI / 6)); | |
context.stroke(); | |
context.closePath(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment