Daily Creative Coding

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

波模様のアニメーション

/**
* animation of abstract waves
*
* @author aa_debdeb
* @date 2016/07/01
*/

float margin = 20;
float radious = 18;
float theta = 120;
float noiseScale = 0.005;
float timeScale = 0.01;
PVector noiseOffset1, noiseOffset2, noiseOffset3;

void setup(){
  size(500, 500);
  noFill();
  strokeWeight(4);  
  noiseOffset1 = new PVector(random(10000), random(10000), random(10000));
  noiseOffset2 = new PVector(random(10000), random(10000), random(10000));
  noiseOffset3 = new PVector(random(10000), random(10000), random(10000));
}

void draw(){
  background(255, 255, 240);
  boolean isDisplaced = false;
  for(float h = -margin; h < height + margin; h += radious){
    for(float w = -margin; w < width + margin; w += 2 * radious){
      if(noise(noiseOffset1.x + w * noiseScale + frameCount * timeScale, noiseOffset1.x + h * noiseScale - frameCount * timeScale) < 0.5){
        float red = int(map(noise(noiseOffset2.x + w * noiseScale + frameCount * timeScale, noiseOffset2.x + h * noiseScale - frameCount * timeScale), 0, 1, 0, 3)) * 85;
        float green = int(map(noise(noiseOffset3.x + w * noiseScale + frameCount * timeScale, noiseOffset3.x + h * noiseScale - frameCount * timeScale), 0, 1, 0, 3)) * 85;
        stroke(red, green, 255);
        float w_;
        if(isDisplaced){
          w_ = w + radious;
        } else {
          w_ = w;      
        }
          arc(w_, h, (radious * 0.33) * 2, (radious * 0.33) * 2, radians(180 + (180 - theta) / 2.0), radians(360 - (180 - theta) / 2.0));
          arc(w_, h, (radious * 0.66) * 2, (radious * 0.66) * 2, radians(180 + (180 - theta) / 2.0), radians(360 - (180 - theta) / 2.0));
          arc(w_, h, radious * 2, radious * 2, radians(180 + (180 - theta) / 2.0), radians(360 - (180 - theta) / 2.0));
      }
    }
    isDisplaced = !isDisplaced;
  }
}