Arrow Shape Using FabricJS

I am trying to create an arrow using shapes of lines and triangles. You can check the demo on jsbin:

http://jsbin.com/xuyere/1/edit?js,output

As you can see from the demonstration, the position of the arrowhead changes with the angle, and this is not true. What am I doing wrong here?

Here's the math I used to calculate the angle:

var dx = x2 - x1,
    dy = y2 - y1,
    angle = Math.atan2(dy, dx);

angle *= 180 / Math.PI;
angle += 90;
+4
source share
1 answer

I changed the value of centerX and CenterY to center, and it got great. Updated code should look like this. Your updated code is http://jsbin.com/nepiqaviqe/1/edit?js,output

var triangle = new fabric.Triangle({
angle: angle,
fill: '#207cca',
top: y2,
left: x2,
height: headLength,
width: headLength,
originX: 'center',
originY: 'center',
selectable: false
  });

  fCanvas.add(triangle);
  }


function createLineArrow(points) {
 var line = new fabric.Line(points, {
strokeWidth: 5,
stroke: '#7db9e8',
originX: 'center',
originY: 'center',
hasControls: false,
hasBorders: false,
hasRotatingPoint: false,
hoverCursor: 'default',
selectable: false
 });
+3
source

Source: https://habr.com/ru/post/1584844/


All Articles