‹ pakt11pakt13 ›

pakt12

See /f0blog/pact-februari/

//pakt12
//ok
int index;
float w, h;
float n;
PGraphics grad;
void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  noStroke();
  smooth();
  index= 0;
  w= width;
  h= height;
  strokeWeight(1);
  grad= createGraphics(width, height, JAVA2D);
  grad.beginDraw();
  grad.background(0);
  createGradient(grad, w*0.5, h*0.5, w, color(0.3*255, 0.3*255, 0.3*255), color(0, 0, 0));
  grad.endDraw();
  fill(255.0, 255.0, 255.0, 0.7*255.0);
}
void draw() {
  image(grad, 0, 0);
  n= sin(index/frameRate*0.125)*150.0+200.0;
  float x= 0, y= 0, xx= 0, yy= 0;
  beginShape();
  for (int i= 0; i<int(n); i++) {
    if (i==0) {
      x= 0.5/n*w;
      y= h*0.5;
    } else if (i%3==1) {
      xx= i/n*w;
      yy= (h*0.25)+(sin((index+(i+3))*(sin((index+1)*0.014)*0.02))*(sin((index+i)*0.015))*(0.225*h));
      vertex(x, y);
      x= xx;
      y= yy;
    } else if (i%3==2) {
      xx= i/n*w;
      yy= (h*0.50)+(sin((index+(i+2))*(sin((index+2)*0.012)*0.02))*(sin((index+i)*0.020))*(0.225*h));
      vertex(x, y);
      x= xx;
      y= yy;
    } else {
      xx= i/n*w;
      yy= (h*0.75)+(sin((index+(i+1))*(sin((index+3)*0.010)*0.02))*(sin((index+i)*0.025))*(0.225*h));
      vertex(x, y);
      x= xx;
      y= yy;
    }
  }
  vertex(width*0.99, height*0.5);
  endShape();
  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);
}