‹ pakt03pakt05 ›

pakt04

See /f0blog/pact-februari/

//pakt04 ok but join style is strange

int n, index;
PGraphics grad;

void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  strokeWeight(3);
  smooth();
  index= 0;
  n= 90;
  grad= createGraphics(width, height, JAVA2D);
  grad.beginDraw();
  grad.background(0);
  createGradient(grad, width*0.5, height*0.5, width*2.0, color(0.5*255.0, 0.7*255.0, 0.5*255.0), color(0, 0, 0));
  grad.endDraw();
}
void draw() {
  float x= width*0.5;
  float y= height*0.5;
  float w= width*0.49;
  float h= height*0.49;
  float spreadx= sin(index*0.005)*5.0;
  float spready= cos(index*0.006)*5.0;
  float wx= w*(sin(index*0.0125)*0.4+0.6);
  float hy= h*(cos(index*0.01)*0.4+0.6);

  image(grad, 0, 0);

  stroke(255.0, 255.0, 255.0, 0.8*255.0);
  float xx= 0.0, yy= 0.0;
  for (int i= 0; i<int(n+(sin(index*0.00876)*50.0)); i++) {
    float px= x+(sin((index+(i*spreadx))*0.05)*sin((index+i)*0.01)*wx);
    float py= y+sin((index+(i*spready))*0.04)*sin((index+i)*0.02)*hy;
    if (i==0) {
      xx= px;
      yy= py;
    } else {
      line(xx, yy, px, py);
      xx= px;
      yy= py;
    }
  }
  index++;
}
void createGradient(PGraphics ctx, float x, float y, float radius, color c1, color c2) {
  ctx.noStroke();
  for (float r= radius; r>=0.0; r--) {
    color col= lerpColor(c1, c2, r/radius);
    ctx.fill(col);
    ctx.ellipse(x, y, r, r);
  }
}