Changing rect color
in
Programming Questions
•
1 year ago
So I'm doing an assignment at the moment and was wondering if anybody could give me assistance on how to change the color of a rect from gray to white with the mousePressed function.
So far this is what i've got, but I'm a little stuck an unsure why it doesn't quite wor
- color white = color(255, 255, 255);
- color gray = color(105, 105, 105);
- int value = gray;
- void setup() {
- size(500, 500);
- }
- void draw() {
- smooth();
- rectMode(CENTER);
- background(0);
- fill(gray); //Fill Gray
- //Row 1
- rect(50, 50, 50, 50);
- rect(100, 50, 50, 50);
- rect(150, 50, 50, 50);
- rect(200, 50, 50, 50);
- rect(250, 50, 50, 50);
- rect(300, 50, 50, 50);
- rect(350, 50, 50, 50);
- rect(400, 50, 50, 50);
- rect(450, 50, 50, 50);
- //Row 2
- rect(50, 100, 50, 50);
- rect(50, 150, 50, 50);
- rect(50, 200, 50, 50);
- rect(50, 250, 50, 50);
- rect(50, 300, 50, 50);
- rect(50, 350, 50, 50);
- rect(50, 400, 50, 50);
- rect(50, 450, 50, 50);
- //Row 3
- rect(100, 100, 50, 50);
- rect(150, 100, 50, 50);
- rect(200, 100, 50, 50);
- rect(250, 100, 50, 50);
- rect(300, 100, 50, 50);
- rect(350, 100, 50, 50);
- rect(400, 100, 50, 50);
- rect(450, 100, 50, 50);
- //Row 4
- rect(100, 150, 50, 50);
- rect(150, 150, 50, 50);
- rect(200, 150, 50, 50);
- rect(250, 150, 50, 50);
- rect(300, 150, 50, 50);
- rect(350, 150, 50, 50);
- rect(400, 150, 50, 50);
- rect(450, 150, 50, 50);
- //Row 5
- rect(100, 200, 50, 50);
- rect(150, 200, 50, 50);
- rect(200, 200, 50, 50);
- rect(250, 200, 50, 50);
- rect(300, 200, 50, 50);
- rect(350, 200, 50, 50);
- rect(400, 200, 50, 50);
- rect(450, 200, 50, 50);
- //Row 6
- rect(100, 250, 50, 50);
- rect(150, 250, 50, 50);
- rect(200, 250, 50, 50);
- rect(250, 250, 50, 50);
- rect(300, 250, 50, 50);
- rect(350, 250, 50, 50);
- rect(400, 250, 50, 50);
- rect(450, 250, 50, 50);
- //Row 7
- rect(100, 300, 50, 50);
- rect(150, 300, 50, 50);
- rect(200, 300, 50, 50);
- rect(250, 300, 50, 50);
- rect(300, 300, 50, 50);
- rect(350, 300, 50, 50);
- rect(400, 300, 50, 50);
- rect(450, 300, 50, 50);
- //Row 8
- rect(100, 350, 50, 50);
- rect(150, 350, 50, 50);
- rect(200, 350, 50, 50);
- rect(250, 350, 50, 50);
- rect(300, 350, 50, 50);
- rect(350, 350, 50, 50);
- rect(400, 350, 50, 50);
- rect(450, 350, 50, 50);
- //Row 9
- rect(100, 400, 50, 50);
- rect(150, 400, 50, 50);
- rect(200, 400, 50, 50);
- rect(250, 400, 50, 50);
- rect(300, 400, 50, 50);
- rect(350, 400, 50, 50);
- rect(400, 400, 50, 50);
- rect(450, 400, 50, 50);
- //Row 10
- rect(100, 450, 50, 50);
- rect(150, 450, 50, 50);
- rect(200, 450, 50, 50);
- rect(250, 450, 50, 50);
- rect(300, 450, 50, 50);
- rect(350, 450, 50, 50);
- rect(400, 450, 50, 50);
- rect(450, 450, 50, 50);
- }
- void mousePressed() {
- if(mousePressed == true) {
- fill(white);
- rect(50, 50, 50, 50);
- rect(100, 50, 50, 50);
- rect(150, 50, 50, 50);
- rect(200, 50, 50, 50);
- rect(250, 50, 50, 50);
- rect(300, 50, 50, 50);
- rect(350, 50, 50, 50);
- rect(400, 50, 50, 50);
- rect(450, 50, 50, 50);
- } else {
- fill(gray);
- rect(50, 50, 50, 50);
- rect(100, 50, 50, 50);
- rect(150, 50, 50, 50);
- rect(200, 50, 50, 50);
- rect(250, 50, 50, 50);
- rect(300, 50, 50, 50);
- rect(350, 50, 50, 50);
- rect(400, 50, 50, 50);
- rect(450, 50, 50, 50);
- }
- }
Thanks :)
- Ethan
1