Arranging an array of objects in a grid

The if in mouseClicked() is only there to check which color you currently have and choose the other one (toggle).

BUT for a pure random, the if is not needed.

Just say (untested):


void mouseClicked(){

    background = color(random(255), random(255), random(255));

}
  • Besides, the usage of random at the beginning of your sketch is running only once. You need to repeat the random command as I just did.
1 Like