Advertisement
KoctrX

Untitled

Dec 13th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. let lineCoords = [100, 100, 300, 100];
  2. let angle = Math.atan2(lineCoords[3] - lineCoords[1], lineCoords[2] - lineCoords[0]);
  3. let headlen = 15;
  4.  
  5. let points = [
  6. {
  7. x: lineCoords[0],
  8. y: lineCoords[1]
  9. },
  10. {
  11. x: lineCoords[2],
  12. y: lineCoords[3]
  13. },
  14. {
  15. x: lineCoords[2] - (headlen) * Math.cos(angle - Math.PI / 2),
  16. y: lineCoords[3] - (headlen) * Math.sin(angle - Math.PI / 2),
  17. },
  18. {
  19. x: lineCoords[2] + (headlen * 2) * Math.cos(angle),
  20. y: lineCoords[3] + (headlen * 2) * Math.sin(angle)
  21. },
  22. {
  23. x: lineCoords[2] - (headlen) * Math.cos(angle + Math.PI / 2),
  24. y: lineCoords[3] - (headlen) * Math.sin(angle + Math.PI / 2),
  25. },
  26. {
  27. x: lineCoords[2],
  28. y: lineCoords[3]
  29. },
  30. {
  31. x: lineCoords[0],
  32. y: lineCoords[1]
  33. }
  34. ];
  35.  
  36.  
  37. pp = new fabric.Polyline(points, {
  38. strokeWidth: 15,
  39. stroke: 'green',
  40. fill: 'red',
  41. noScaleCache: false,
  42. objectCaching: false,
  43. statefullCache: false,
  44. centeredScaling: false,
  45. lockScalingFlip: true,
  46. cacheKey: `group-${Date.now()}`,
  47. diff_mb: 0,
  48. diff_mt: 0,
  49. _name: 'graphics', cornerStyle: 'graphic',
  50. transparentCorners: false,
  51. cornerColor: '#249acf',
  52. cornerStrokeColor: '#ffffff',
  53. borderColor: '#ffffff',
  54. cornerSize: 13,
  55. borderDashArray: [2, 4],
  56. rotatingPointOffset: 23,
  57. lockSkewingX: true,
  58. lockSkewingY: true,
  59.  
  60. _type: 'Line',
  61. _controlsVisibility: { mb: true, mtr: true },
  62. centeredScaling: true,
  63. padding: 15,
  64. customParams: { editComponent: "ArrowSettings", editProps: null }
  65. })
  66. _LIB.app.fabricCanvas.add(pp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement