I have an array that generates rectangles for me, but how can I add the lines to each rectangle in fabricjs

Viewed 17

** I have a matrix of rectangles, and I have a for loop to generate lines, but it only appears in the first rectangle, how can it be done so that it is also generated in the other rectangles. this is how it is currently adj image .. enter link description here**

  rect: any;
  numLine=3;

    for (let i = 0; i < 4; i++) {
      for (let j = 0; j < 2; j++) {
        this.rect = {
          width: 90,
          height: 90,
          top: 90 * j,
          left: 90 * i,
          hasControls: false,
          stroke: '#000000',
          strokeWidth: 2,
          fill: 'transparent',
          borderColor: 'transparent',
          cornerStrokeColor: ''
        };
        let c = new fabric.Rect(this.rect);
        this.canvas.add(c);

      }
    }


**here I generate the lines invoking the measure of the rectangle to divide with the quantities of lines.**

    for (let i = 1; i < this.numLine; i++) {
      let line = {
        top: this.rect.height / this.numLine * i,
        stroke: 'red',
      }
      let l = new fabric.Line([0, 0, 90, 0],line)
      this.canvas.add(l);
    }
0 Answers
Related