xxxxxxxxxx
41
class Block {
constructor(x, y) {
// let midPoint = floor(width/size/2);
// this.x = midPoint;
// this.y = midPoint;
// this.margin = 10;
// this.dmargin = 1;
this.x = floor(random(cols));
this.y = floor(random(rows));
this.margin = 10;
}
display(grid) {
this.x = floor(mouseX / size);
this.y = floor(mouseY / size);
for (let i=-this.margin; i<this.margin; i++) {
for (let j=-this.margin; j<this.margin; j++) {
let x = this.x + i;
let y = this.y + j;
x = constrain(x, 0, cols - 1);
y = constrain(y, 0, rows - 1);
if (grid[x][y] == 1) {
fill(255);
} else {
fill(0);
}
rect(x*size, y*size, size, size);
}
}
// if (this.margin > floor(width/size/2) || this.margin < 0) {
// this.dmargin *= -1;
// }
// this.margin += this.dmargin;
}
}