Grid
in
Programming Questions
•
2 years ago
As this is my first actual attempt at programming, please forgive my idiocy. I am trying to make a 15x15 grid where I can color each individual square black at a mouseclick. I can fairly easily make a 15x15 grid, but when I click it turns the whole grid black rather than any given square. Here is that code:
I have since figured out I need to make an object for each box so that i can vary the fill individually (am I right?). I can make an object, but I dont want to individually define 225 separate objects typing in the locations manually, and I was wondering if there was a way to create a slew of objects, similar to the way I create a bunch of rectangles up above?
void setup() {
size(1020, 1120);
background(255);
}
void draw() {
strokeWeight(5);
rect(400, 20, 600, 600);
strokeWeight(1);
for (int a=400; a<=960; a=a+40) {
for (int b=20; b<=580; b=b+40) {
rect(a, b, 40, 40);
}
}
}
void mousePressed() {
if (mouseButton == LEFT) {
fill(0);
} else if (mouseButton == RIGHT) {
fill(255);
} else {
fill(126);
}
}
I have since figured out I need to make an object for each box so that i can vary the fill individually (am I right?). I can make an object, but I dont want to individually define 225 separate objects typing in the locations manually, and I was wondering if there was a way to create a slew of objects, similar to the way I create a bunch of rectangles up above?
1