Why is my grid attempt a 45 angle trial instead of a grid ?

Hi! I got this sketch where i want to draw a grid of objects... but instead of drawing a grid, it draws a 45 angle trail.. got any idea where is the problem ? thanks!

https://codepen.io/giorgiomartini/pen/aNgQKV

Tagged:

Answers

  • Answer ✓

    Use your nested loop variables as god intended:

      // - - - draw grid - - - //
      // precalculate for efficiency
      var stepX = width/cols;
      var stepY = height/rows;
    
      for(var i = 0; i < cols; i++)
        for (var j = 0; j < rows; j++) {
          // no need to store gridX/Y
          // ...unless used elsewhere
          paints.push(new Paint(stepX * i , stepY * j ) );
        }
      }
    
  • Aweosome! thanks so much blindfish ! :D

Sign In or Register to comment.