I'm trying to calculate certain rectangle positions and sizes in the grid, and I'd like to randomize them per each tile.
Can something like this be done:
for (let x = 0; x < p.width; x += tiles) {
for (let y = 0; y < p.height; y += tiles) {
let subItemPerTile = p.random(itemsPerTile);
// This should contain random X/Y options using -i, +i, *i in a list
let coordinatesPerTile = [['x', 'y'], ['x-i', 'y-i'], ['x+i', 'y-i']];
for (let i = tilesInGrid; i > 0; i--) {
p.fill(p.color(p.random(255)));
let s = (tiles * i) / subItemPerTile;
// This is working method where I'd like to substitute randomly, x,y,s from the list above
// p.square(x, y, (tiles * i) / subItemPerTile);
//This was desired way, and I had 's' as the part of the list, but removed it until I figure out if this can be done this way
//p.square.apply(null, p.random(coordinatesPerTile);
//p.square(...coordinatesPerTile);
// This is me debugging on second item in the list
let coords = coordinatesPerTile[1];
x = eval(coords[0]);
y = eval(coords[1]);
console.log(coords[0]);
// let s = eval(coords[2]);
// console.log(s);
// Below works for coordinatesPerTile[0], but not for coordinatesPerTile[1], I don't understand why
p.square(x, y, s);
}
coordinatesPerTile
. – Bergi