Fill in the grid with colors Part 2
in
Programming Questions
•
4 months ago
When I preview this, the grey color does not stay on the grid like a brush. What is the problem with the code?
final int rows = 20, columns = 20;
final int scale = 20;
void setup(){
//background(255);
size(400,400);
fill(255);
stroke(0);
//rect(x,y,scale,scale);
}
/* for (int i = 0; i < columns; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
int x = i*scale;
int y = j*scale;
*/
void draw() {
for (int i = 0; i < columns; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
int x = i*scale;
int y = j*scale;
if( //test to see if mouse is within the current square being drawn
(mouseX > x && mouseX < x + scale) &&
(mouseY > y && mouseY < y + scale) ) {
fill(127);
} else {
fill(255);
}
stroke(0);
rect(x,y,scale,scale);
}
}
}
1