We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So far, this creates 16 ellipses that are equidistant in hue. Is there any way to create a new array of colors based off the pre-existing one where the colors are in a random order, and then plug in that array for the ellipses? Thanks in advance!
color[] colors = new color[16];
int k;
void setup() {
colorMode(HSB, 16, 100, 100);
size(800, 950);
background(0, 0, 100);
for (k=0; k<16; k++) {
colors[k] = color(k+1, 75, 100);
}
}
void draw() {
int k= 0;
for (float i = 150; i < 701; i = i+166) {
for (float j = 150; j < 701; j = j+166) {
noStroke();
// int index = int(random(colors.length));
fill(colors[k]);
ellipse(i, j, 100, 100);
k++;
}
}
}
Answers
I think You could use Collections.shuffle, but as color is an
int
and lists can't have primitives there is some extra work to be donecode edited - added "press any key to re-sort" : )
or you can make your won shuffle function, like the one below : )
Edited the code above to add a "re-sort" option. Only in Collections approach.
Edited again, now in both approaches : )
A simpler lazy approach for a free shuffle() method is by using the new Processing 2+'s data structure IntList:
http://processing.org/reference/IntList.html