swaying balls
@author
int LOOP = 120;
int NUM = 24;
void setup(){
size(500, 500);
noStroke();
fill(255);
}
void draw(){
background(0);
translate(width / 2, height / 2);
for(int i = 0; i < NUM; i++){
float angle = TWO_PI / NUM * i;
float time = float((frameCount + LOOP / NUM * i) % LOOP) / LOOP;
float radius = time < 0.5 ? map(time, 0, 0.5, 0, 150): map(time, 0.5, 1.0, 150, 200);
float size = time < 0.5 ? map(time, 0, 0.5, 0, 10): map(time, 0.5, 1.0, 10, 0);
size *= map(sin(time * PI * 6 + HALF_PI), -1, 1, 0.8, 1.2);
float osc = map(sin(time * PI * 6), -1, 1, -10, 10);
osc *= time < 0.66 ? map(time, 0, 0.66, 0, 1): map(time, 0.66, 1.0, 1, 0);
pushMatrix();
rotate(angle);
translate(radius, osc);
ellipse(0, 0, size, size);
popMatrix();
}
}