Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1007301 // drawArrowHead

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (56L/1K).

import java.awt.geom.*;

static float drawArrowHead_length = 2f;

static void drawArrowHead(Graphics2D g, double x1, double y1, double x2, double y2, double size) {
  if (y2 == y1 && x2 == x1) ret;
  
  Path2D.Double arrowHead = new Path2D.Double();
  arrowHead.moveTo(0, 0);
  double l = drawArrowHead_length*size;
  arrowHead.lineTo(-size, -l);
  arrowHead.lineTo(size, -l);
  arrowHead.closePath();

  new AffineTransform tx;
  double angle = Math.atan2(y2-y1, x2-x1);
  tx.translate(x2, y2);
  tx.rotate(angle-Math.PI/2);

  AffineTransform old = g.getTransform();
  g.transform(tx);
  g.fill(arrowHead);
  g.setTransform(old);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007301
Snippet name: drawArrowHead
Eternal ID of this version: #1007301/17
Text MD5: 2ac89bf9438b0d21704900a1af2cf185
Transpilation MD5: 4f7826c74f17feccdf9743645f2e3a2b
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-28 20:53:20
Source code size: 656 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 545 / 588
Version history: 16 change(s)
Referenced in: [show references]