Try out yourself ( click in the display area)
Source
final int collection_size = 16; // collection size
final int collection_active = 4; // activated count
final int collection_active2 = 8;
int[] collection;
final int circle_d = 40;
final int circle_r = circle_d / 2;
final int circle_gap = 10;
void setup(){
// size( (circle_d + circle_gap * 2) * collection_size, circle_d + circle_gap * 2);
size(860, 60);
// Using boring initial condition, the left most x elements are initially active
collection = new int[collection_size];
for( int i = 0; i < collection_size; i++ ){
if( i < collection_active ){
collection[i] = 1;
}else if (i < collection_active2){
collection[i] = 2;
}else {
collection[i] = 0;
}
}
randomSeed( millis());
}
void draw(){
// Draw them
background(0);
stroke(255);
for( int i = 0; i < collection_size; i++ ){
if( collection[i] == 1 ){
fill(255,0,0);
}else if( collection[i] == 2 ){
fill(0,255,0);
}else{
fill(0,0,255);
}
ellipse( circle_gap + (circle_gap + circle_d) * (i + 1) - circle_r, circle_r + circle_gap, circle_d,circle_d);
}
}
void mousePressed(){
for( int i = 0; i < collection_size - 1; i++ ){
for( int j = i + 1; j < collection_size; j++ ){
int rnd = (int)random(65536);
if( rnd % 2 == 1 ){
int temp_val = collection[i];
collection[i] = collection[j];
collection[j] = temp_val;
println("Swapped:["+i+","+j+"]");
}
}
}
}