xxxxxxxxxx
57
class Field {
constructor(n, m, w, h) {
this.n = n;
this.m = m;
this.w = w;
this.h = h;
this.pointed = []
for (let i = 0; i < this.n; i++) {
this.pointed.push([]);
for (let j = 0; j < this.m; j++)
this.pointed[i].push(false);
}
}
tovector() {
let vector = [];
for (let i = 0; i < this.n; i++)
for (let j = 0; j < this.m; j++)
{
vector.push((this.pointed[i][j]) ? 1 : -1);
}
return vector;
}
pointed(x, y) {
let ni = floor(x / this.w);
let nj = floor(y / this.h);
if (ni >= 0 && ni < this.m && nj >= 0 && nj < this.n)
this.pointed[nj][ni] = !this.pointed[nj][ni];
}
clear() {
for (let i = 0; i < this.n; i++) {
for (let j = 0; j < this.m; j++)
this.pointed[i][j] = false;
}
}
display() {
background(31);
stroke(255, 0, 155);
for (let i = 0; i < this.n; i++)
for (let j = 0; j < this.m; j++) {
if (this.pointed[i][j])
fill(255, 215, 0);
else
noFill();
rect(j * this.w, i * this.h, this.w, this.h);
}
}
}