読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

なびく面

3D
/*
* surface in the wind
*
* @author aa_debdeb
* @date 2016/08/06
*/

int num = 50;
int step = 20;
float scale = 0.1;
PVector[] offsets;

void setup(){
  size(500, 500, P3D);
  fill(220, 20, 60);
  stroke(0);
  strokeWeight(1);
  offsets = new PVector[3];
  for(int i = 0; i < 3; i++){
    offsets[i] = new PVector(random(10000), random(10000), random(10000));
  }
}

void draw(){
  background(255);
  float time = frameCount * 0.003;
  PVector[][] points = new PVector[num][num];
  for(int x = 0; x < num; x++){
    for(int y = 0; y < num; y++){
      if(x == 0 && y == 0){
        float w = map(noise(x * scale + offsets[0].x, y * scale + offsets[0].y, time), 0, 1, -step, step);
        float h = map(noise(x * scale + offsets[1].x, y * scale + offsets[1].y, time), 0, 1, -step, step);
        float d = map(noise(x * scale + offsets[2].x, y * scale + offsets[2].y, time), 0, 1, -step, step);
        points[x][y] = new PVector(w, h, d);  
      } else if(x == 0) {
        float w = points[x][y - 1].x + map(noise(x * scale + offsets[0].x, y * scale + offsets[0].y, time), 0, 1, -step / 2, step);
        float h = points[x][y - 1].y + map(noise(x * scale + offsets[1].x, y * scale + offsets[1].y, time), 0, 1, -step / 2, step);
        float d = points[x][y - 1].z + map(noise(x * scale + offsets[2].x, y * scale + offsets[2].y, time), 0, 1, -step, step);
        points[x][y] = new PVector(w, h, d);      
      } else if(y == 0){
        float w = points[x - 1][y].x + map(noise(x * scale + offsets[0].x, y * scale + offsets[0].y, time), 0, 1, -step / 2, step);
        float h = points[x - 1][y].y + map(noise(x * scale + offsets[1].x, y * scale + offsets[1].y, time), 0, 1, -step / 2, step);
        float d = points[x - 1][y].z + map(noise(x * scale + offsets[2].x, y * scale + offsets[2].y, time), 0, 1, -step, step);      
        points[x][y] = new PVector(w, h, d);      
      } else {
        float w = (points[x - 1][y].x + points[x][y - 1].x) / 2.0 + map(noise(x * 0.1 + offsets[0].x, y * 0.1 + offsets[0].y, time), 0, 1, -step / 2, step);
        float h = (points[x - 1][y].y + points[x][y - 1].y) / 2.0 + map(noise(x * 0.1 + offsets[1].x, y * 0.1 + offsets[1].y, time), 0, 1, -step / 2, step);
        float d = (points[x - 1][y].z + points[x][y - 1].z) / 2.0 + map(noise(x * 0.1 + offsets[2].x, y * 0.1 + offsets[2].y, time), 0, 1, -step, step);
        points[x][y] = new PVector(w, h, d);
      }
    }
  }
  
  for(int x = 0; x < num - 1; x++){
    for(int y = 0; y < num - 1; y++){
      beginShape();
      vertex(points[x][y].x, points[x][y].y);
      vertex(points[x + 1][y].x, points[x + 1][y].y);
      vertex(points[x + 1][y + 1].x, points[x + 1][y + 1].y);
      vertex(points[x][y + 1].x, points[x][y + 1].y);
      endShape(CLOSE);
    }
  }
}
f:id:aa_debdeb:20160731213935j:plain