using array grid, how to change it individually
in
Programming Questions
•
7 months ago
I am trying to get a grid made from an array to change colors with a left click or right click, left turns it black, and right turns it yellow. But when i click it turns the whole thing turns to a color instead of the individual boxes. any help would be appreciated. here is the code
- int boxsize = 100;
- int cols, rows;
- void setup()
- {
- size(600, 600);
- cols = width/boxsize;
- rows = height/boxsize;
- }
- void draw()
- {
- background(255);
- for (int i = 0; i < cols; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- int x = i*boxsize;
- int y = j*boxsize;
- if(mouseX > x && mouseX < (x + boxsize) &&
- mouseY > y && mouseY < (y + boxsize))
- {
- if (mousePressed && (mouseButton == LEFT))
- {
- fill(0);
- }
- else if(mousePressed && (mouseButton == RIGHT))
- {
- fill(255,255,0);
- }
- }
- rect(x, y, boxsize, boxsize);
- stroke(100);
- }
- }
- }
1