‹ pakt18pakt20 ›

pakt19

See /f0blog/pact-februari/

//pakt19
//ok
int index, n;
float w, h;
float speed, disorder, rad;
float[][] bubbles;
PGraphics grad;
void setup() {
  size(640, 480);
  frameRate(60);
  smooth();
  noStroke();
  index= 0;
  w= width;
  h= height;
  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, w*0.5, h*0.5, w, 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(w*0.5, h*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))*w*0.4*b[0], 
      cos(theta+((sin(index*0.0012)*0.25+1.0)*i))*h*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++;
}
//Simple Radial Gradient by Ira Greenberg, modified by /f0
void createGradient (PGraphics ctx, float x, float y, float radius, color c1, color c2) {
  float px = 0, py = 0, angle = 0;
  // calculate differences between color components 
  float deltaR = red(c2)-red(c1);
  float deltaG = green(c2)-green(c1);
  float deltaB = blue(c2)-blue(c1);
  // hack to ensure there are no holes in gradient
  // needs to be increased, as radius increases
  float gapFiller = 8.0;
  for (int i=0; i< radius; i++) {
    for (float j=0; j<360; j+=1.0/gapFiller) {
      px = x+cos(radians(angle))*i;
      py = y+sin(radians(angle))*i;
      angle+=1.0/gapFiller;
      color c = color(
        (red(c1)+(i)*(deltaR/radius)), 
        (green(c1)+(i)*(deltaG/radius)), 
        (blue(c1)+(i)*(deltaB/radius)) 
        );
      ctx.stroke(c);
      ctx.rect(px, py, 1, 1);
    }
  }
  // adds smooth edge 
  // hack anti-aliasing
  ctx.noFill();
  ctx.strokeWeight(3);
  ctx.ellipse(x, y, radius*2, radius*2);
}