xxxxxxxxxx
26
// rect grid with offset
// as array of color pointer only, and delete the class thing
let x = 12, y = x, w = 30, h = w, offset = 2, grid = 15, many = grid * grid;
let mytiles = []; // array long "many" remember random color pointer only
var mycolors= [[255,0,0],[255,128,0],[255,255,0],[0,255,0],[0,0,255],[127,0,255],[255,102,178],[80,80,80]]; // array of 8 colors
function setup() {
createCanvas(500, 500);
noStroke();
for (let i = 0; i < many; i++) mytiles[i]=int(random(8)); // make random tiles color array
//}
//function draw() { // no need for draw loop now
background(0);
draw_myRects();
}
function draw_myRects() {
for (let i = 0; i < many; i++) {
let posx = x + (i % grid) * (w + offset);
let posy = y + (floor(i / grid)) * (h + offset);
fill(mycolors[mytiles[i]][0],mycolors[mytiles[i]][1],mycolors[mytiles[i]][2]);
rect(posx, posy, w, h);
}
}