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

Daily Creative Coding

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

二色の地層

/**
* two-color layers
*
* @author aa_debdeb
* @date 2016/07/26
*/

PVector nOffset1, nOffset2;

void setup(){
  size(500, 500);
  noStroke(); 
  nOffset1 = new PVector(random(10000), random(10000), random(10000));
  nOffset2 = new PVector(random(10000), random(10000), random(10000));
}

void draw(){
  float[] ys = new float[width + 1];
  for(int x = 0; x <= width; x++){
    ys[x] = height;
  }
  boolean alt = true;
  while(isIn(ys)){
    if(alt){
      fill(0);
    } else {
      fill(184, 134, 11);
    }
    beginShape();
    for(int x = 0; x <= width; x++){
      vertex(x, ys[x]);
    }
    vertex(width, 0);
    vertex(0, 0);
    endShape(CLOSE);
    
    for(int x = 0; x <= width; x++){
      if(alt){
        ys[x] -= map(noise(x * 0.003 + nOffset1.x, ys[x] * 0.001 + nOffset1.y, frameCount * 0.003 + nOffset1.z), 0, 1, 0, map(ys[x], 0, height, 1, 20));
      } else {
        ys[x] -= map(noise(x * 0.003 + nOffset2.x, ys[x] * 0.001 + nOffset2.y, frameCount * 0.003 +  + nOffset2.z), 0, 1, 0, map(ys[x], 0, height, 20, 1));      
      }
    }
    alt = !alt;
  }  
}

boolean isIn(float[] ys){
  for(int x = 0; x < ys.length; x++){
    if(ys[x] > 0){
      return true;
    }
  }
  return false;
}