press and hold mouse, move horizontally to change pitch, vertical to change volume
xxxxxxxxxx
// Sound setup
let osc;
let reverb;
let dotX = []; // pitch
let dotY = []; // volume
let meowImg, pawImg_1, pawImg_2;
function preload() {
meowImg = loadImage('meow.png');
pawImg_1 = loadImage('paw1.png');
pawImg_2 = loadImage('paw2.png');
}
function setup() {
createCanvas(600, 400);
noCursor();
// Theremin Sound setup
osc = new p5.Oscillator();
osc.setType('triangle');
reverb = new p5.Reverb();
delay = new p5.Delay();
osc.disconnect();
reverb.process(osc, 3, 5);
delay.process(osc, 0.12, 0.5, 2300);
}
function draw() {
background(220);
noStroke();
image(meowImg, 0, 0);
// Dots grid
for (let x = 1; x <= 12; x++) {
dotX[0] = 0;
dotX[x] = dotX[x - 1] + 30 * pow(1.059, x);
for (let y = 0; y < 5; y++) {
dotY[y] = y * 40;
fill(255);
rect(dotX[x], dotY[y] + 50, 10);
}
}
// Theremin Sound
theremin();
// User hands icon
hands();
}
function mousePressed() {
osc.start();
}
function mouseReleased() {
osc.stop();
}
function theremin() {
let pitch = map(mouseX, dotX[1], dotX[12], 261.6, 493.8, true);
let vol = map(mouseY, dotY[0] + 50, dotY[4] + 50, 0.8, 0, true);
osc.freq(pitch);
osc.amp(vol);
}
function hands() {
if (mouseIsPressed) {
image(pawImg_2, mouseX - 20, mouseY, 50, 50);
} else {
image(pawImg_1, mouseX - 20, mouseY, 50, 50);
}
}