diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-10-04 11:04:37 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-10-04 11:04:37 +0200 |
| commit | 18d860cff5230576e76c80a5cc2d3442165be4a1 (patch) | |
| tree | c0037c4df9e2e1fa69d915b04ea9c8c9450f9544 /public/js/p5_custom.js | |
| parent | e0ed5e12d919a919c796c6e8c1d1d251e31c263f (diff) | |
Update
Diffstat (limited to 'public/js/p5_custom.js')
| -rw-r--r-- | public/js/p5_custom.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/public/js/p5_custom.js b/public/js/p5_custom.js new file mode 100644 index 0000000..b25e636 --- /dev/null +++ b/public/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)) +} |
