xxxxxxxxxx
39
var items = [];
COLS = 6;
MARG = 45;
function setup() {
rectMode(CENTER)
textAlign(CENTER);
createCanvas(400, 400);
for (var y = MARG; y < height-MARG ; y += MARG ) {
for (var x = MARG ; x < width-MARG ; x += (width/COLS))
items.push(new Item(x,y ))
}
}
class Item {
static uid = 0;
constructor(x,y) {
this.pos = createVector(x,y)
this.id = ++Item.uid;
}
show() {
rect (this.pos.x ,this.pos.y, MARG-3)
text(this.id, this.pos.x-5,this.pos.y+5)
}
}
function draw() {
background(220);
for (const i of items){
i.show();
}
noLoop();
}