Ok so I slightly misunderstood, the nature of intList there I thought it worked exactly like an arrayList.
Cannot say why this won’t allow you to append twice, however could you use the following approach
for (int k = 0; k < cells.length*2; k++) {
//inventory_1.set (k, lerpColor (from, to, k*step));
if(k&2==0)inventory_1.append (lerpColor (from, to, k*step));
else inventory_1.append (color (255));
//inventory_1.append (color (0)); *** does not work when I add second color
}
I might be misunderstanding what you are trying to achieve though.
Final check
Cell [] cells = new Cell[9];
IntList inventory_1;
void setup() {
size (400, 600);
color [] shuffledInventory = getColorListShuffled();
int x = 0, y = x;
int w = width, h = height/cells.length;
for (int i = 0; i < cells.length; i++) {
cells[i] = new Cell (x, y+i*h, w, h, shuffledInventory[i]);
}
}
void draw() {
background (51);
for (int i = 0; i < cells.length; i++) {
cells[i].display();
}
fill(0);
text(inventory_1.size(),100,100);
}
color [] getColorListShuffled() {
color from = color (random(255), random(255), random(255));
color to = color (random(255), random(255), random(255));
float step = 1.0f / (cells.length -2); // *** when I append second color I change to cells.length -3
inventory_1 = new IntList (0);
for (int k = 0; k < cells.length; k++) {
inventory_1.set (k, lerpColor (from, to, k*step));
//inventory_1.append (lerpColor (from, to, k*step));
inventory_1.append (color (255));
inventory_1.append (color (0));
inventory_1.append (color (0));
//*** does not work when I add second color
}
inventory_1.shuffle();
return inventory_1.array();
}
// CLASS ----------------------------------------------
class Cell {
float x, y, w, h;
color clr;
Cell (float tempX, float tempY, float tempW, float tempH, color tempClr){
x = tempX;
y = tempY;
w = tempW;
h = tempH;
clr = tempClr;
}
void display(){
noStroke ();
fill (clr);
rect (x, y, w, h);
}
}
This is what I get with three append cycles. The size of the list.size()
is 3* bigger than cell.length
- 1