xxxxxxxxxx
GRIDSIZE = 20;
class Row {
ArrayList < int > cells;
int length = 0;
Row(int size) {
cells = new ArrayList < int > ();
length = size;
for (int c = 0; c < length; c++)
{
cells.add(0);
}
}
int get(int cell) {
return cells.get(cell);
}
}
ArrayList < Row > grid = new ArrayList < Row > ();
void setup() {
size(800, 800);
background(200, 200, 200);
for (int j = 0; j < (width / GRIDSIZE); j++) {
grid.add(new Row((width / GRIDSIZE)));
}
}
void draw() {
noStroke();
for (int y = 0; y < int((width / GRIDSIZE)); y++) {
for (int x = 0; x < int((width / GRIDSIZE)); x++) {
if (grid.get(y).cells.get(x) == 0) {
fill(0, 0, 0);
} else
fill(255, 255, 255);
rect(x * GRIDSIZE + GRIDSIZE / 10, y * GRIDSIZE + GRIDSIZE / 10, (GRIDSIZE - GRIDSIZE / 5), (GRIDSIZE - GRIDSIZE / 5));
}
}
if (mousePressed) {
int mX = (mouseX - mouseX % GRIDSIZE) / GRIDSIZE;
int mY = (mouseY - mouseY % GRIDSIZE) / GRIDSIZE;
grid.get(mY).cells.set(mX, 1);
}
}