float FADE_TIME = 120;
float OVERLAP = 9;
ArrayList revealers;
void setup() {
size(800, 800);
background(0);
revealers = new ArrayList();
initializeFades();
}
void draw() {
background(255);
for (int i = revealers.size ()-1; i >= 0; i --) {
Revealer r = (Revealer) revealers.get(i);
r.run();
}
}
void initializeFades() {
float a =3*PI/2;
float rad = 25;
float blockwidth = 9;
for (int i=0; i<10; i++) {
for (int j=0; j<10; j++) {
float r, g, b;
r = 200;
g = 34;
b = 90;
float alpha = random(0, 255);
float x1, y1, x2, y2, x3, y3, x4, y4;
float increment = 2*PI/10;
x1 = cos(a);
y1 = sin(a);
x2 = cos(a+increment);
y2 = sin(a+increment);
x3 = x2*(rad+blockwidth);
y3 = y2*(rad+blockwidth);
x4 = x1*(rad+blockwidth);
y4 = y1*(rad+blockwidth);
x1 *= rad;
y1 *= rad;
x2 *= rad;
y2 *= rad;
stroke(255);
println(alpha);
revealers.add(new Revealer(x1, y1, x2, y2, x3, y3, x4, y4, i*10*FADE_TIME/OVERLAP+j*FADE_TIME/OVERLAP, color(r, g, b, alpha)));
a += 2*PI/10; //splitting the circle into 10 parts
}
rad += 12;
}
}
class Revealer {
PVector p1;
PVector p2;
PVector p3;
PVector p4;
float offset;
color c;
Revealer(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float _offset, color _c) {
p1 = new PVector(x1, y1);
p2 = new PVector(x2, y2);
p3 = new PVector(x3, y3);
p4 = new PVector(x4, y4);
offset = _offset;
c = _c;
}
void run() {
render();
}
void render() {
//start at the middle
pushMatrix();
translate(width/2, height/2);
noStroke();
// we create a variable which will fade in and out our
// shape. We assign it a value between 1 (full) and 0 (empty)
// based on where we are relative to our start time
// measured against FADE_TIME
float fade = map(frameCount-offset, 0, FADE_TIME, 0, 1);
// we make sure it's not negative or greater than 1
fade = constrain(fade, 0, 1);
// we modify the alpha of our color based on fade, so now
// it wil be blank at frameCount+offset frames, and fully
// filled in by frameCount+offset+FADE_TIME frames
fill(red(c), green(c), blue(c), alpha(c)*fade);
//we draw our shape
beginShape();
vertex(p1.x, p1.y);
vertex(p2.x, p2.y);
vertex(p3.x, p3.y);
vertex(p4.x, p4.y);
endShape();
popMatrix();
}
}