xxxxxxxxxx
45
let ctracker;
let capture;
let fatOsc;
let vol;
function setup() {
createCanvas(400, 300);
capture = createCapture(VIDEO);
capture.size(400, 300);
capture.hide();
ctracker = new clm.tracker();
ctracker.init();
ctracker.start(capture.elt);
// (osc) => (gain) => (speakers)
vol = new Tone.Gain(0).toDestination();
fatOsc = new Tone.FatOscillator("Ab3", "sawtooth", 40).connect(vol).start();
}
function draw() {
// flip camera over y axis
translate(width, 0);
scale(-1, 1);
image(capture, 0, 0);
const positions = ctracker.getCurrentPosition();
if (positions) {
positions.forEach(p => {
noStroke();
fill("red");
circle(p[0], p[1], 4);
});
const b = createVector(positions[60][0], positions[60][1]);
const t = createVector(positions[57][0], positions[57][1]);
const mw = b.sub(t).mag();
// between 4 and 28
const newVol = map(mouseX, 0, width, 0, 0.3);
vol.gain.value = newVol;
const freq = map(mw, 4, 28, 50, 150);
fatOsc.frequency.value = freq;
}
}