int angleCount = 100;
ArrayList<Box> boxes;
PVector angle1, angle2;
void setup(){
size(500, 500, P3D);
noFill();
stroke(255, 192);
boxes = new ArrayList<Box>();
for(int i = 0; i < 200; i++){
boxes.add(new Box());
}
angle1 = new PVector(random(TWO_PI), random(TWO_PI), random(TWO_PI));
angle2 = new PVector(random(TWO_PI), random(TWO_PI), random(TWO_PI));
}
void draw(){
background(0);
translate(width / 2, height / 2, 0);
int count = frameCount % angleCount;
float rate = float(count) / angleCount;
rotateX(angle1.x * (1 - rate) + angle2.x * rate);
rotateY(angle1.y * (1 - rate) + angle2.y * rate);
rotateZ(angle1.z * (1 - rate) + angle2.z * rate);
for(Box box: boxes){
box.display();
}
if(count == angleCount - 1){
angle1 = angle2;
angle2 = new PVector(random(TWO_PI), random(TWO_PI), random(TWO_PI));
}
}
class Box{
PVector pos;
float size;
Box(){
float x = random(-200, 200);
float y = random(-200, 200);
float z = random(-200, 200);
pos = new PVector(x, y, z);
size = random(20, 100);
}
void display(){
pushMatrix();
translate(pos.x, pos.y, pos.z);
box(size);
popMatrix();
}
}