Advertisement
KoctrX

Untitled

Nov 19th, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. function drawRuller(element=false){
  2. cr.control_canvas.getObjects().forEach((el)=>{
  3. if(el.is_ruller){
  4. el.remove();
  5. }
  6. });
  7.  
  8. function createLine(x,y, size=13){
  9. return new fabric.Line([
  10. 0, 0,
  11. 0, 100
  12. ], {
  13. left: 0,
  14. top: 0,
  15. originX: 'left',
  16. originY: 'top',
  17. stroke: "green",
  18. strokeWidth: 3
  19. });
  20. }
  21.  
  22. let width = element.width,
  23. half_width = Math.ceil(width/2),
  24. height = element.height,
  25. half_height = Math.ceil(height/2)
  26. start_point_w = Math.ceil(width/2),
  27. start_point_h = Math.ceil(height/2),
  28. offset_x = element.left+half_width,
  29. offset_y = element.top+half_height,
  30. lines = [];
  31.  
  32. let distance = Math.ceil(half_width/5);
  33.  
  34. for(let i=0; i<half_width; i+=distance){
  35. lines.push(createLine(0,half_width+distance, 13));
  36. lines.push(createLine(0,half_width-distance, 13));
  37. }
  38.  
  39. const rect = new fabric.Rect({ left: 0, top: 0, width: 300, height: 300, fill: 'rgba(0,0,0,0)' });
  40. let group = new fabric.Group([...lines, rect],{
  41. width: 300,
  42. height: 300,
  43. top: 100,
  44. left: 100,
  45. scaleX: 1,
  46. scaleY: 1,
  47. });
  48.  
  49. group.is_ruller = true;
  50. //group.add(...lines);
  51.  
  52. window.lines = lines;
  53.  
  54. console.log("group", group);
  55. cr.control_canvas.add(group)
  56. cr.control_canvas.renderAll();
  57.  
  58. }
  59.  
  60. drawRuller(cr.control_canvas.getActiveObject());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement