void setup() {
size(500, 500);
}
void draw() {
float progress = frameCount % 120;
float sigmoid = 1/(1+exp(-(progress-60)/10));
float percent = sigmoid;
int phase = int(frameCount / 120 % 2);
float black = map(percent,0,1,0,255);
float white = map(percent,0,1,255,0);
if(phase==0) {
float tmp = black;
black = white;
white = tmp;
}
float s = width/3;
float[] x, y, a;
if (phase == 0) { //black or white
x = new float[]{0, 2*s, 3*s, s,width/2};
y = new float[]{s, 0, 2*s, s*3,height/2};
a = new float[]{0, PI/2, -2*PI/2, -PI/2,0};
}else {
x = new float[]{s,3*s,2*s,0,width/2};
y = new float[]{0,s,3*s,2*s,height/2};
a = new float[]{0,PI/2,-PI,-PI/2,0};
}
noStroke();
background(phase==0?white:black);
for (int i = 0; i < x.length; i++) {
if(i<4) rectMode(CORNER);
else rectMode(CENTER);
pushMatrix();
translate(x[i], y[i]);
rotate(a[i] +(phase>0?1:-1) * PI/2 * (percent));
fill(phase==0 ? black : white);
float w = s,h = s;
if(i>3) w = h = percent * s;
rect(0, 0, w, h);
popMatrix();
}
}