‹ pakt08pakt10 ›

pakt09

See /f0blog/pact-februari/

//pakt09
//ok
int index, n, m;
float rows, cols;
float magic;
PGraphics grad;
void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  noStroke();
  index= 0;
  n= 1000;
  m= 0;
  rows= 3;
  cols= 4;
  magic= 50;
  grad= createGraphics(width, height, JAVA2D);
  grad.beginDraw();
  grad.background(0);
  createGradient(grad, width*0.5, height*0.5, width, color(0.5*255, 0.5*255, 0.5*255), color(0, 0, 0));
  grad.endDraw();
  fill(255.0, 255.0, 255.0, 0.85*255.0);
}
void draw() {
  float w= width;
  float h= height;
  image(grad, 0, 0);
  if (m<n) {
    m= m+1;
  }
  for (int i= 0; i<m; i++) {
    float px= (rows+i)%w;
    float py= ((cols+i)*(i%magic))%h;
    rect(px, py, 8.0*sin((index+i)*0.012), 8.0*cos((index+i)*0.011));
  }
  magic= magic+(sin(index*0.001)*0.01);
  rows= rows+(sin(index*0.0004));
  cols= cols+(sin(index*0.0005));
  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);
}