Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

三次元の花びら

/**
* 3D petals
*
* @author aa_debdeb
* @date 2016/10/11
*/

float maxRadious = 300;
PVector offset1, offset2;
float scale1 = 0.02;
float scale2 = 0.01;
color c1 = color(255);
color c2 = color(255, 77, 172);

void setup(){
  size(640, 640, P3D);
//  stroke(255);
  noStroke();
  offset1 = new PVector(random(10000), random(10000));
  offset2 = new PVector(random(10000), random(10000));
}

void draw(){
  background(240);
  translate(width / 2, height * 3.0 / 4.0);
  rotateX(PI / 4);
  rotateZ(map(mouseX, 0, width, -HALF_PI, HALF_PI));
  rotateX(map(mouseY, 0, height, -PI / 6, PI / 6));
  float angStep = 10;
  float time = frameCount * 0.01;
  for(float radious = maxRadious; radious > 0; radious -= 10){
//    fill(map(radious, 0, maxRadious, red(c1), red(c2)),
//         map(radious, 0, maxRadious, green(c1), green(c2)),
//         map(radious, 0, maxRadious, blue(c1), blue(c2)));
    fill(lerpColor(c1, c2, radious / maxRadious));
    for(float angle = 0; angle < 360; angle += angStep){
      float rad1 = radians(angle);
      float rad2 = radians(angle + angStep);
      PVector p1 = new PVector(radious * cos(rad1), radious * sin(rad1));
      PVector p2 = new PVector(radious * cos(rad2), radious * sin(rad2));      
      float nr1 = map(noise(p1.x * scale1 + offset1.x, p1.y * scale1 + offset1.y, time), 0, 1, -50, 50);
      float nr2 = map(noise(p2.x * scale1 + offset1.x, p2.y * scale1 + offset1.y, time), 0, 1, -50, 50);
      PVector np1 = new PVector((radious + nr1) * cos(rad1), (radious + nr1) * sin(rad1));
      PVector np2 = new PVector((radious + nr2) * cos(rad2), (radious + nr2) * sin(rad2));
      float z1 = 200 + map(noise(p1.x * scale2 + offset2.x, p1.y * scale2 + offset2.y, time), 0, 1, -100, 100);
      float z2 = 200 + map(noise(p2.x * scale2 + offset2.x, p2.y * scale2 + offset2.y, time), 0, 1, -100, 100);
      beginShape();
      vertex(0, 0, 0);
      vertex(np1.x, np1.y, z1);
      vertex(np2.x, np2.y, z2);
      endShape();
    }
  }
}
f:id:aa_debdeb:20161003214839j:plain