Daily Creative Coding

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

残像のつくオシロスコープ

/**
* ghost sine wave
*
* @author aa_debdeb
* @date 2017/01/08
*/

void setup(){
  size(640, 480);
  background(0);
}

void draw(){
  noStroke();
  fill(0, 40);
  rect(0, 0,width, height);
  stroke(0, 255, 0);
  strokeWeight(3);
  noFill();
  beginShape();
  for(int w = 0; w <= width; w++){
    vertex(w, map(sin(w * 0.1 + frameCount * 0.1), -1, 1, -120, 120) + height / 2);
  }
  endShape();

  float ampOffset = map(mouseX - pmouseX, -200, 200, 30, -30);
  float angOffset = map(mouseY - pmouseY, -200, 200, -30, 30);
  beginShape();
  for(int w = 0; w <= width; w++){
    vertex(w, map(sin((w + angOffset) * 0.1 + frameCount * 0.1), -1, 1, -120, 120) + height / 2 + ampOffset);
  }
  endShape();
}
f:id:aa_debdeb:20170104212658j:plain