Daily Creative Coding

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

積み重なった波

f:id:aa_debdeb:20161023075810j:plain

stacked tooth - OpenProcessing

/**
* stacked tooth
*
* @author aa_debdeb
* @date 2016/10/29
*/

color bg;
color[] c;

void setup(){
  size(640, 480);
  colorMode(HSB, 360, 100, 100);
  noStroke();
  mousePressed();  
}

void mousePressed(){
  float sat = random(40, 80);
  float bri = random(60, 80);
  bg = color(random(360), sat, bri);
  c = new color[3];
  for(int i = 0; i < 3; i++){
    c[i] = color(random(360), sat, bri);
  }
}

void draw(){
  background(bg);
  float[][] layers = new float[3][width + 1];
  float t = frameCount * 0.01;
  for(int li = 0; li < 3; li++){
    for(int w = 0; w < width + 1; w++){
      float ynoise =map(noise(w * 0.002 + 10000 + frameCount * 0.01), 0, 1, 0, 200);
      if(li == 0){
        layers[li][w] = map(sin(w * 0.07 + frameCount * 0.2), -1, 1, 400, 500) - ynoise;
      } else {
        layers[li][w] = layers[li - 1][w] - ynoise;
      }
    }
  }
  for(int li = 2; li >= 0; li--){
    fill(c[li]);
    beginShape();
    vertex(0, height);
    for(int w = 0; w < width + 1; w++){
      vertex(w, layers[li][w]);
    }
    vertex(width, height);
    endShape(CLOSE);
  }
}