let icons = [" ", " ", " ", " ", " ", " "];
colorMode(HSB, 360, 100, 100, 100);
video = createCapture(VIDEO);
ctracker = new clm.tracker();
ctracker.start(video.elt);
emotions = new emotionClassifier();
emotions.init(emotionModel);
captureButton = createButton('记录美好瞬间');
captureButton.position(width / 2 - captureButton.width / 2, height / 2 - captureButton.height / 2);
rect(0, 0, width, height);
positions = ctracker.getCurrentPosition();
var cp = ctracker.getCurrentParameters();
predictedEmotions = emotions.meanPredict(cp);
if (isPlaying && predictedEmotions) {
for (let i = 0; i < oscs.length; i++) {
freq = constrain(map(predictedEmotions[i].value, 0, 1, 0, 1000), 100, 500);
amp = constrain(map(predictedEmotions[i].value / 8, 0, 1, 0, 0.5), 0, 0.5);
cellW = (width - offset * 2 - margin * (predictedEmotions.length - 1)) / predictedEmotions.length;
for (var i = 0; i < predictedEmotions.length; i++) {
let x = map(i, 0, predictedEmotions.length - 1, offset, width - offset - cellW);
let y = height - margin * 3;
let h = map(i, 0, predictedEmotions.length, 180, 240);
let s = sq(predictedEmotions[i].value) * 100;
rect(x, y, cellW, -predictedEmotions[i].value * cellH);
textAlign(CENTER, CENTER);
let label = Object.values(predictedEmotions[i])[0];
if (label.toLowerCase() === 'happy' && predictedEmotions[i].value > 0.5) {
text("记录美好瞬间", width / 2, height / 2);
text(nf(predictedEmotions[i].value, 1, 2), x + cellW / 2, y - predictedEmotions[i].value * cellH - 25);
if (predictedEmotions[i].value > 0.5) {
text(icons[i], x + cellW / 2, y - predictedEmotions[i].value * cellH - 25);
for (var i = 0; i < positions.length - 3; i++) {
ellipse(positions[i][0], positions[i][1], 5, 5);
function mousePressed() {
if (captureButton.elt.offsetWidth > 0) {
function captureAndSave() {
let newCanvas = createGraphics(width, height);
newCanvas.image(video, 0, 0);
saveCanvas(newCanvas, 'screenshot', 'png');