xxxxxxxxxx
93
let capture;
let tracker;
let lip;
let leftEye;
let rightEye;
let heartPos;
let micPos;
function preload() {
lip = loadImage('lip.png');
leftEye = loadImage('left eye.png');
rightEye = loadImage('right eye.png');
}
function setup() {
createCanvas(640, 480);
background(0);
capture = createCapture(VIDEO);
capture.size(width, height);
capture.hide();
// load clmtrackr functions:
tracker = new clm.tracker(); // create a new clmtrackr object
tracker.init(); // initialize the object
tracker.start(capture.elt) // start tracking the video element capture.elt
}
function draw() {
imageMode(CORNER);
image(capture, 0, 0, width, height);
let positions = tracker.getCurrentPosition(); //update the tracker with current positions
//try hearts
// textSize(50);
// text('❤️',100,100);
if (positions.length > 0) {
imageMode(CENTER);
image(leftEye, positions[27][0], positions[27][1], 90, 50);
image(rightEye, positions[32][0], positions[32][1], 90, 50);
image(lip, positions[60][0], positions[60][1], 90, 50);
// array for hearts
heartPos = [[positions[1][0] - 50, positions[1][1]],
[positions[2][0] - 35, positions[2][1]],
[positions[3][0] - 20, positions[3][1]],
[positions[13][0] + 30, positions[13][1]],
[positions[12][0] + 15, positions[12][1]],
[positions[11][0] + 10, positions[11][1]]];
// use loop to run heartPos array
textSize(30);
for (let i = 0; i < 6; i++){
text('❤️', heartPos[i][0], heartPos[i][1]);
}
// textSize(30); //hearts
// text('❤️', positions[1][0] - 50, positions[1][1]);
// text('❤️', positions[2][0] - 35, positions[2][1]);
// text('❤️', positions[3][0] - 20, positions[3][1]);
// text('❤️', positions[13][0] + 30, positions[13][1]);
// text('❤️', positions[12][0] + 15, positions[12][1]);
// text('❤️', positions[11][0] + 10, positions[11][1]);
// if (dist(positions[47][0], positions[47][1], positions[53][0], positions[53][1]) > 30) {
//strobe lights & Mics
frameRate(50)
if (mouseIsPressed) {
background(random(255), random(255), random(255), 100);
//array for mic
micPos = [[positions[5][0] - 80, positions[5][1]+80],
[positions[7][0] - 80, positions[7][1]+80],
[positions[9][0] - 50, positions[9][1]+80]];
//use loop to run micPos array
textSize(100);
for (let i=0; i<3; i++){
text('🎤', micPos[i][0], micPos[i][1]);
}
// textSize(100); //mics
// text('🎤', positions[5][0] - 80, positions[5][1] + 80);
// text('🎤', positions[7][0] - 80, positions[7][1] + 80);
// text('🎤', positions[9][0] - 50, positions[9][1] + 80);
}
}
}