From eb92a8ef2a3fc4ea86d07db6b690c902c26d647f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 4 Oct 2021 10:32:14 +0200 Subject: Update --- www/js/p5_custom.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 www/js/p5_custom.js (limited to 'www') diff --git a/www/js/p5_custom.js b/www/js/p5_custom.js new file mode 100644 index 0000000..b25e636 --- /dev/null +++ b/www/js/p5_custom.js @@ -0,0 +1,15 @@ + +draw_arrow=function(p,x1,y1,x2,y2){ + p.push() + p.strokeWeight(5) + p.line(x1,y1,x2,y2) + offset=5 + var angle = p.atan2(y1 - y2, x1 - x2); //gets the angle of the line + p.translate(x2, y2); //translates to the destination vertex + p.rotate(angle-p.HALF_PI); //rotates the arrow point + p.triangle(-offset*0.8, offset, offset*0.8, offset, 0, -offset/2); //draws the arrow point as a triangle + p.pop(); + + // Return the center of the arrow + return(p.createVector(x1+(x2-x1)/2,y1+(y2-y1)/2)) +} -- cgit v1.2.3