‹ pakt10pakt12 ›

pakt11

See /f0blog/pact-februari/

//pakt11
//ok
int index;
float rowsMid, colsMid, rows, cols, w, h;
PGraphics grad;
void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  noStroke();
  smooth();
  index= 0;
  rowsMid= 22.0;
  colsMid= 20.0;
  w= width;
  h= height;
  scale(0.96, 0.96);
  translate(5.0, 5.0);
  grad= createGraphics(width, height, JAVA2D);
  grad.beginDraw();
  grad.background(0);
  createGradient(grad, w*0.5, h*0.5, w, color(0.6*255, 0.5*255, 0.5*255), color(0, 0, 0));
  grad.endDraw();
  fill(255.0);
}
void draw() {
  rows= rowsMid+(sin(index*0.0015)*10.0);
  cols= colsMid+(sin(index*0.0024)*10.0);
  image(grad, 0, 0);
  float x0= 0, y0= 0, x1= 0, y1= 0, x2= 0, y2= 0;
  beginShape();
  for (int x= 0; x<=int(rows); x++) {
    for (int y= 0; y<=int(cols); y++) {
      x1= (x/rows*w)+sin(index+(x*y)*32.0);
      y1= (y/cols*h)+cos(index+(x*y)*24.0);
      x2= (x/cols*w)+sin(index+(x*y)*32.0);
      y2= (y/rows*h)+cos(index+(x*y)*24.0);
      vertex(x0, y0);
      vertex(x1, y1);
      x0= x2;
      y0= y2;
    }
  }
  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);
}