I want to append black and white to an array of lerped colors. Works okay when I append the first color, but not when I append the second color. What am I doing wrong?
// MAIN -----------------------------
Cell [] cells = new Cell[9];
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();
}
}
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
IntList inventory_1 = new IntList (cells.length);
for (int k = 0; k < cells.length; k++) {
inventory_1.set (k, lerpColor (from, to, k*step));
inventory_1.append (color (255));
//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);
}
}