‹ pakt09pakt11 ›

pakt10

See /f0blog/pact-februari/

//pakt10
//ok - but looks a little bit different
int index, n;
float rows, cols;
float rowMod, colMod;
float magic;
PGraphics grad;
void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  smooth();
  index= 0;
  n= 1200;
  rows= 11;
  cols= 12;
  rowMod= 2.0;
  colMod= 3.0;
  magic= 0.0;
  grad= createGraphics(width, height, JAVA2D);
  grad.beginDraw();
  grad.background(0);
  createGradient(grad, width*0.5, height*0.5, width, color(0.2*255, 0.2*255, 0.5*255), color(0, 0, 0));
  grad.endDraw();
  stroke(255.0, 255.0, 0.2*255.0, 0.85*255.0);
}
void draw() {
  float w= width;
  float h= height;
  float r= rows+(sin(index*0.013)*rowMod)+(sin(index*0.00133)*rowMod*0.56);
  float c= cols+(cos(index*0.022)*colMod)+(cos(index*0.00122)*colMod*0.45);
  image(grad, 0, 0);
  for (int i= 0; i<n; i++) {
    float px= (r+i)%w;
    float py= ((c+i)*(i%(magic+1.0)))%h;
    line(px, py, px+(10.0+sin((index+i)*0.02)), py+(10.0*cos((index+i)*0.03)));
  }
  rows= rows+(sin(index*0.0004));
  cols= cols+(sin(index*0.0005));
  index++;
  magic= (magic+0.00002)%15.0;
}
//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);
}