Appending more than one color to an array loop of colors

Finally got this to work. Posting solution in case anyone else may be seeking how to add specific color(s) to a color array generated with a for loop, and then randomly shuffle.
And thank you @paulgoux!, your suggestions did help me think about this with fresh eyes. :slightly_smiling_face:

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);
  IntList inventory_1 = new IntList (cells.length);

  for (int k = 0; k < cells.length-2; k++) {
    inventory_1.set (k, lerpColor (from, to, k*step));
    
  }
  inventory_1.append(#000000); // add black to the array
  inventory_1.append(#ffffff); // add white to the array
  inventory_1.shuffle(); // all colors shuffled
  

  return inventory_1.array();
}
2 Likes