Where is the error in my code?


https://editor.p5js.org/eternity95097@gmail.com/sketches/TvAwrnaMB

pls. check out the examples,
https://p5js.org/examples/arrays-array-2d.html

a more simplified example:

let myarray = [];
let maxarray =5;


function setup() {
  createCanvas(200,200);
  for (let x = 0; x < maxarray; x++) {
    myarray[x] = [];                     // create nested array
    for (let y = 0; y < maxarray; y++)   myarray[x][y] = x*y;
  }
  noLoop(); // Run once and stop
}

function draw() {
	 for (let x = 0; x < maxarray; x++) console.log(myarray[x]);
}

prints:

  • [0, 0, 0, 0, 0]
  • [0, 1, 2, 3, 4]
  • [0, 2, 4, 6, 8]
  • [0, 3, 6, 9, 12]
  • [0, 4, 8, 12, 16]

while that works i think the problem in your code is also with the
[x/len]
there are only integer number 0 …N allowed ( matrix index )
but you seem to calculate ? floats
and i worry they are not understood as int index.

1 Like