1

I'm trying to pick a random color for strokeline from an array list. From the program, it indicates that random() expect parameter like random(float). But I feel a bit stuck of how to correct it. Below is my code:

int n = 200;
drop[] d;

color[] colors  = {  
 #013a63, 
 #01497c, 
 #014f86, 
 #2a6f97, 
 #2c7da0, 
 #468faf, 
 #61a5c2, 
 #89c2d9, 
 #a9d6e5,
};

void setup() {
  size(1080, 720);
  stroke(random(colors));
  d = new drop[n];
  for(int i = 0; i < d.length; i ++) {
    d[i] = new drop(random(width), random(-10, 20), random(5));
  }
  
}

void draw() {
  background(1, 42, 74,10);
  for(int i = 0; i < d.length; i ++) {
    d[i].show();
    d[i].update();
  }
  
}
Liz
  • 31
  • 3

1 Answers1

3

Generate a random # between 0 and 8, then use that index:

stroke(colors[(int)random(8)]);

or dynamically using the length or colors (in case it changes):

stroke(colors[(int)random(colors.length)]);
George Profenza
  • 50,687
  • 19
  • 144
  • 218
aflo7
  • 58
  • 5