pakt19
See /f0blog/pact-februari/
//pakt19
int index, n;
float speed, disorder, rad;
float[][] bubbles;
PGraphics grad;
void setup() {
size(640, 480);
frameRate(60);
smooth();
noStroke();
index= 0;
n= 200;
rad= 25.0;
bubbles= new float[n][3];
for (int i= 0; i<n; i++) {
bubbles[i][0]= 0.0;
bubbles[i][1]= 0.0;
bubbles[i][2]= 1.0;
}
grad= createGraphics(width, height, JAVA2D);
grad.beginDraw();
grad.background(0);
createGradient(grad, width*0.5, height*0.5, width*2.0, color(255, 77, 77), color(0, 0, 0));
grad.endDraw();
}
void draw() {
speed= sin(index*0.02)*0.01+0.065;
disorder= sin(index*0.0022)*25.0+25.0;
image(grad, 0, 0);
translate(width*0.5, height*0.5);
for (int i= 0; i<n; i++) {
float[] b= new float[3];
b= bubbles[i];
float theta= ((float(i)/n)+sin(index*0.0001))*TWO_PI;
fill(255.0, 255.0, 255.0, (1.0-b[2])*255.0);
ellipse(
sin(theta+((sin(index*0.0008)*0.25+1.0)*i))*width*0.4*b[0],
cos(theta+((sin(index*0.0012)*0.25+1.0)*i))*height*0.4*b[1],
rad*b[2]*2,
rad*b[2]*2
);
float dxyz= (sin((index+(i*speed*disorder))*0.01)*0.1+0.15)*speed;
bubbles[i][0]= (b[0]+dxyz)%1.0;
bubbles[i][1]= (b[1]+dxyz)%1.0;
bubbles[i][2]= (b[2]+dxyz)%1.0;
}
index++;
}
void createGradient(PGraphics ctx, float x, float y, float radius, color c1, color c2) {
ctx.noStroke();
for (float r= radius; r>=0.0; r--) {
color col= lerpColor(c1, c2, r/radius);
ctx.fill(col);
ctx.ellipse(x, y, r, r);
}
}