I made a version for you
Remark
As I said, technically it changes only the order in which we draw. The color and position don’t change (probably not what you want).
Explanation
- First I made 2 parallel arrays (parallel in so far as the data of the 0th ellipse is in x_Pos_Ellipse[0] AND colorEllipse[0]. Think of 2 lists where we look up data from the same line (0th line) to get data for the same ellipse.
- This in setup()
- Then I use a for-loop to display the ellipses using the data from the 2 arrays
- This in draw().
the tricky part
Now the tricky part. Instead of using i
in draw() as the index (line number) for the arrays, I use another list named order
. This list initially holds 0,1,2,3 (just like i runs up) but I can shuffle the list. So it is 3201 or so. Now i still runs up from 0 to 3 so order.get(i) in the for loop gives me 3201 as index.
Hope this helps.
Warm regards,
Chrisir
Full Code
float t=0.0;
float[] x_Pos_Ellipse = new float [4];
color[] colorEllipse = new color [4];
IntList order=new IntList();
// -------------------------------------------
void setup() {
size(300, 300);
frameRate(10);
for (int i=0; i<x_Pos_Ellipse.length; i++) {
order.append(i);
}
println(order);
// order.shuffle();
println(order);
float ac = (t+.4);
ac = map(ac, 0, 1, 0, width);
// ellipse(ac, height/2, 60, 60);
x_Pos_Ellipse[0]=ac;
colorEllipse[0]=color(255, 0, 0);
ac = (t+.5);
ac = map(ac, 0, 1, 0, width);
// ellipse(ac, height/3, 60, 60);
x_Pos_Ellipse[1]=ac;
colorEllipse[1]=color(0, 255, 0);
ac = (t+.6);
ac = map(ac, 0, 1, 0, width);
// ellipse(ac, height/3, 60, 60);
x_Pos_Ellipse[2]=ac;
colorEllipse[2]=color(0, 0, 255);
ac = (t+.7);
ac = map(ac, 0, 1, 0, width);
// ellipse(ac, height/3, 60, 60);
x_Pos_Ellipse[3]=ac;
colorEllipse[3]=color(255, 0, 255);
}
void draw() {
background(0);
fill(255);
text("Hit any key to shuffle the order of drawing", 17, 17);
for (int i=0; i<x_Pos_Ellipse.length; i++) {
fill(colorEllipse[order.get(i)] );
ellipse(x_Pos_Ellipse[order.get(i)], height/3, 60, 60);
}
}
// -------------------------------------------
void keyPressed () {
// shuffle
order.shuffle();
}
//