Daily Creative Coding

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

振幅変調

/**
* amplitude modulatoin
*
* @author aa_debdeb
* @date 2016/04/02
*/

ArrayList<Float> values;
float ac, as, avc, avs;

void setup(){
  size(500, 500);
  frameRate(180);
  stroke(255);
  noFill();
  ac = 0.0;
  as = 0.0;
  avc = PI / 64;
  avs = PI / 16;
  values = new ArrayList<Float>();
  for(int w = 0; w < width; w++){
    values.add(getValue());
    step();
  }
}

void draw(){
  background(0);
  translate(0, height / 2);
  beginShape();
  for(int w = 0; w < values.size(); w++){
    float v = values.get(w);
    float h = map(v, -1, 1, -height / 2, height / 2);
    vertex(w, h);
  }
  endShape();
  
  avc = map(mouseX, 0, width, PI / 128, PI / 16);
  avs = map(mouseY, 0, height, PI / 128, PI / 16);
  
  step();
  values.remove(0);
  values.add(getValue());
  
}

void step(){
  ac += avc;
  as += avs;
}

float getValue(){
  return sin(ac) * sin(as);
}