but that is the right way:
//Grid data
int w = 500;
int h = 500;
int scl = 50;
int cols = w/scl;
int rows = h/scl;
int index = cols*rows;
//Object data
Object[] thing = new Object[index];
void setup() {
size(500, 500);
int k = 0;
for (int y = 0; y<rows; y++) {
for (int x = 0; x<cols; x++) {
thing[k] = new Object((scl/2)+(x*scl), (scl/2)+(y*scl), k*2.7, (x+y)*2, random(PI));
k++;
println(k);
}
}
}
void draw() {
background(0);
for (int i = 0; i < index; i++) {
thing[i].showObject();
}
}
class Object {
float x;
float y;
float size;
float col;
float boost = 0.1;
float rot = 1;
PVector loc;
PVector rotation;
PVector center;
Object(float _x, float _y, float _col, float _size, float _rot) {
rot = _rot;
x = _x;
y = _y;
size = _size;
col = _col;
}
void showObject() {
rectMode(CENTER);
fill(255);
//stroke(255);
noStroke();
pushMatrix();
translate(x,y);
rotate(rot);
rect(0, 0, size, size);
popMatrix();
}
}