# イージングで飛び出る円

/**
* easing test
*
* @author aa_debdeb
* @date 2016/11/20
*/

float time = 0;
float duration = 200;
ArrayList<Circle> circles;
color c1, c2;

void setup(){
size(640, 640);
mousePressed();
}

void draw(){
translate(width / 2, height / 2);
background(255);
for(Circle c: circles){
c.display();
}
time += 1;
}

void mousePressed(){
c1 = color(random(255), random(255), random(255));
c2 = color(random(255), random(255), random(255));
circles = new ArrayList<Circle>();
for(int i = 0; i < 10000; i++){
float locSize = map(sqrt(random(1)), 0, 1, 0, 250);
float locAng = random(TWO_PI);
PVector loc = new PVector(locSize * cos(locAng), locSize * sin(locAng));
boolean isOverlapped = false;
for(Circle other: circles){
isOverlapped = true;
continue;
}
}
if(!isOverlapped){
}
}
time = 0;
}

class Circle {

PVector loc;
color c;

loc = _loc;
c = lerpColor(c1, c2, sq(loc.mag() / 250));
}

void display(){
fill(c);
noStroke();
float r = time > duration ? radius: easeOutElastic(time, 0, radius, duration);
ellipse(loc.x, loc.y, r * 2, r * 2);
}

float easeOutElastic(float t, float b, float c, float d){
float s = 1.70158;
float a = c;
if(t == 0)
return b;
t /= d;
if(t == 1)
return b + c;
float p = d * 0.3;
if(a < abs(c)){
a = c;
s = p / 4;
} else {
s = p / (2 * PI) * asin(c / a);
}
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * PI) / p) + c + b;
}
}