Daily Creative Coding

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

急にノイズが入るサイン波

/**
* sine / noise
*
* @author aa_debdeb
* @date 2017/01/09
*/

void setup(){
  size(640, 480);
  stroke(255, 255, 30);
  strokeWeight(2);
  noFill();
}

void draw(){
  background(0, 0, 20);

  float noiseRate = pow(abs(sin(frameCount * 0.01)), 150);
  beginShape();
  for(int w = 0; w <= width; w++){
    float h = map(sin(w * 0.1 + frameCount * 0.2), -1, 1, -120, 120) * (1.0 - noiseRate) +
                     map(random(1), 0, 1, -120, 120)  * noiseRate;
    vertex(w, h + height / 2.0);
  }
  endShape();

}
f:id:aa_debdeb:20170104213901j:plain