Hello.
Right now I have a random grid of colors chosen from an array. I would like mousePressed to check the color of the rectangle clicked, determine which it is, and then select a different color based on the result.
I am not sure which direction to move in going forward.
Thanks!
- color grey = color(230);
- color peach = color(0,0,255);
- color aqua = color(255,0,0);
- int[] colors = {
- grey,peach,aqua
- };
- int[] colorsPressed = {
- grey,peach,aqua
- };
- int randColor;
- int randPressed;
- void setup () {
- size(705,504);
- background(0);
- smooth();
- noStroke();
- noLoop();
- }
- int sqWidth = 100;
- int sqHeight = 100;
- int margin = 1;
- void draw () {
- for (int x=0;x<=width;x=x+(sqWidth+margin)) {
- for(int y = 0;y<=height;y=y+(sqHeight+margin)) {
- fill(randPressed);
- bgSquare(x,y);
- }
- }
- }
- void bgSquare(int xPos,int yPos) {
- randColor = int(random(colors.length));
- fill(colors[randColor]);
- rect(xPos,yPos,sqWidth,sqHeight);
- }
- void mousePressed() {
- randPressed = int(random(colorsPressed.length));
- fill(colorsPressed[randPressed]);
- println(randPressed);
- }
1