xxxxxxxxxx
47
let osc1; //sound
let visual1; //sketch
function setup() {
createCanvas(windowWidth, windowHeight);
rectMode(CENTER);
//osc1
osc1 = new p5.Oscillator();
osc1.setType('sine');
osc1.freq(240);
osc1.amp(0); // 0 to 1.0
osc1.start();
//visual1
visual1 = new v1();
}
function draw() {
background(220);
if(keyIsDown(LEFT_ARROW)){
osc1.amp(1,0.5);
osc1.freq(240);
visual1.show();
}else if
(keyIsDown(RIGHT_ARROW)){
osc1.amp(1,0.5);
osc1.freq(540);
}else {
osc1.amp(0, 0.5);
}
}
class v1{
constructor(){
this.x = 20;
this.y = 20;
this.w = 20;
this.h = 20;
}
show(){
ellipse(this.x, this.y, this.w, this.h);
}
}