Arranging an array of objects in a grid

NB: color stores r and g and b
so you can simplify your code

in the class

you have this in the class


//////////////////////////////////////////

class Button {
  float x, y, w, h;
  color r;
  color g;
  color b;

No. You want


//////////////////////////////////////////

class Button {
  float x, y, w, h;
  color colRect;

in the constructor

you have this in the class / constructor

color tempR, color tempG, color tempB, 

doesn’t make sense

what you want is color tempColor

Then say colRect=tempColor ;

Usage of fill

fill(colRect);

1 Like