Daily Creative Coding

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

二次元のパーリンノイズを格子状に可視化する

/**
* Perlin Noise in Grid
*
* @author aa_debdeb
* @date 2016/02/02
*
*/

int X = 25;
int X_INTERVAL = 20;
int Y = 25;
int Y_INTERVAL = 20;

float noiseX;
float noiseY;
float noiseT;
float noiseXScale;
float noiseYScale;
float noiseTScale;

void setup(){
  size(500, 500);
  frameRate(30);
  strokeWeight(1);
  noiseX = random(100);
  noiseY = random(100);
  noiseT = random(100);
  noiseXScale = 0.05;
  noiseYScale = 0.05;
  noiseTScale = 0.03;
}

void draw(){
  background(0);
  for(int xi = 0; xi <= X; xi++){
    for(int yi = 0; yi <= Y; yi++){
      float x = xi * X_INTERVAL;
      float y = yi * Y_INTERVAL;
//      ellipse(x, y, 5, 5);
      if(xi != X){
        float s = (xi + 1) * X_INTERVAL;
        float t = yi * Y_INTERVAL;
        float alpha = map(noise(noiseX + x, noiseY + y, noiseT + frameCount * noiseTScale) + noise(noiseX + s, noiseY + t, noiseT + frameCount * noiseTScale), 0, 2, 0, 255);
        stroke(255, alpha);  
        line(x, y, s, t);
      }
      if(yi != Y){
        for(int xj = xi - 1;  xj <= xi + 1; xj++){
          if(0 <= xj && xj <= X){
            float s = xj * X_INTERVAL;
            float t = (yi + 1) * Y_INTERVAL;
            float alpha = map(noise(noiseX + x, noiseY + y, noiseT + frameCount * noiseTScale) + noise(noiseX + s, noiseY + t, noiseT + frameCount * noiseTScale), 0, 2, 0, 255);
            stroke(255, alpha);             
            line(x, y, s, t);
          }   
        }
      }
    }
  }
}