xxxxxxxxxx
// remember to add the sound library : p5.sound
var osc; // this is a variable which we will use for an oscillator
var env; // this is a variable which we wlll use for the envelope
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
// take 0.1 seconds to get to level 1, then 0.5 seconds to get to level 0
env = new p5.Envelope(0.01, 1, 0.3, 0);
osc = new p5.Oscillator(); // make an oscillator
osc.setType('sine'); // options are 'sine', 'sawtooth', 'triangle', 'square'
osc.start(); // start it
osc.amp(0);
}
function draw() {
line(pmouseX, pmouseY, mouseX, mouseY);
}
function mouseClicked()
{
playit();
}
function playit()
{
ellipse(mouseX, mouseY, 20, 20);
osc.freq(mouseX); // frequency to the X axis (in Hz)
env.mult(1-mouseY/height); // volume for the note
env.play(osc);
}