You can make a array of colors and then in the for loop increment an int variable as an index for it
example 1
color[] colorList = {
color(0), // black
color(255), // white
// Red,Green,Blue
color(255, 0, 0),
color(0, 255, 0),
color(0, 0, 255),
// colors inbetween 1 (with 55)
color(55, 255, 255),
color(255, 55, 255),
color(255, 255, 55),
// colors inbetween 2 (with 0)
color(0, 255, 255),
color(255, 0, 255),
color(255, 255, 0)
};
void setup() {
size(1100, 600);
background(111);
}//func
void draw() {
final int sizeRect=70; // size of one rectangle
int x=20; // x position
// loop over all colors
for (color currentColor : colorList) {
// display rect with that color
fill(currentColor);
rect(x, 100, sizeRect, sizeRect);
// increment x position
x+=sizeRect+10;
}//for
}//func
//
and for your code
color[] colorList = {
color(0), // black
color(255), // white
// Red,Green,Blue
color(255, 0, 0),
color(0, 255, 0),
color(0, 0, 255),
// colors inbetween 1 (with 55)
color(55, 255, 255),
color(255, 55, 255),
color(255, 255, 55),
// colors inbetween 2 (with 0)
color(0, 255, 255),
color(255, 0, 255),
color(255, 255, 0)
};
void setup() {
size(1100, 600);
background(111);
}//func
void draw() {
int k=0;
// loop over all colors
for (int j = 1; j <= 3; j++)
{
for (int i = 1; i <= 2; i++)
{
fill(colorList[k%11]);
rect (i*40-28, j*70+30,
35, 35);
k++;
}
}
}//func
//