xxxxxxxxxx
let menu = [
{ name: "Entrada: Bruschetta" },
{ name: "Prato Principal: Risoto de Camarão" },
{ name: "Sobremesa: Cheesecake" }
];
let currentDishIndex = -1;
let eating = false;
let noivos = "Alice e João";
// Para integrar ml5.js e detectar a abertura de boca
let video;
let mouthOpen = false;
let faceMesh;
let options = { maxFaces: 1, refineLandmarks: false, flipped: false };
let faces = [];
function preload() {
faceMesh = ml5.faceMesh(options);
}
function setup() {
createCanvas(800, 600);
video = createCapture(VIDEO);
video.size(width, height);
video.hide();
faceMesh.detectStart(video, gotFaces);
}
function gotFaces(results) {
// Save the output to the faces variable
faces = results;
}
function gotPoses(poses) {
if (poses.length > 0) {
pose = poses[0].pose;
let nose = pose.keypoints.find(k => k.part === "nose");
let mouthBottom = pose.keypoints.find(k => k.part === "mouthBottom");
if (nose && mouthBottom) {
let lipDistance = dist(
nose.position.x,
nose.position.y,
mouthBottom.position.x,
mouthBottom.position.y
);
mouthOpen = lipDistance > 50; // Detecta se a boca está aberta (ajustar conforme necessário)
}
}
}
function draw() {
background(200);
let bocaAberta = false;
for (let i = 0; i < faces.length; i++) {
let face = faces[i];
bocaAberta |= isMouthOpen(face.keypoints);
}
/*
for (let i = 0; i < faces.length; i++) {
let face = faces[i];
let bocaAberta = isMouthOpen(face.keypoints);
for (let j = 0; j < face.keypoints.length; j++) {
let keypoint = face.keypoints[j];
if(bocaAberta){
fill(0, 255, 0);
}else{
fill(255, 0, 0);
}
noStroke();
circle(keypoint.x, keypoint.y, 5);
}
}
*/
drawOverlay();
if (currentDishIndex === -1) {
drawStartMenu();
} else {
drawDish();
if (bocaAberta) {
eating = true;
}
if (eating) {
eatDish();
}
}
}
function isMouthOpen(keypoints) {
// Define points around the mouth (FaceMesh indices)
const topLip = keypoints[13]; // Top of upper lip
const bottomLip = keypoints[14]; // Bottom of lower lip
// Define points around the face for size estimation (e.g., between the eyes)
const leftEye = keypoints[33]; // Left eye (can also use other points like eyes)
const rightEye = keypoints[133]; // Right eye
const mouthDistance = dist(topLip.x, topLip.y, bottomLip.x, bottomLip.y);
const faceWidth = dist(leftEye.x, leftEye.y, rightEye.x, rightEye.y);
// Use faceWidth to scale the threshold dynamically
// Here, we're using a small fraction of the face width to adjust the threshold
const threshold = faceWidth * 0.5; // Adjust threshold proportionally to the face width
// Determine if the mouth is open
return mouthDistance > threshold;
}
function drawOverlay() {
fill(255, 255, 255, 200);
rect(50, 50, width - 100, height - 100, 20);
fill(0);
textSize(32);
textAlign(CENTER, CENTER);
text(`Bem-vindos ao menu degustação de ${noivos}`, width / 2, 100);
if (currentDishIndex === -1) {
drawMenu();
}
}
function drawMenu() {
textSize(24);
textAlign(LEFT, CENTER);
let xStart = 100;
let yStart = 150;
for (let i = 0; i < menu.length; i++) {
fill(200);
rect(xStart, yStart + i * 60, width - 200, 50, 10);
fill(0);
text(menu[i].name, xStart + 20, yStart + i * 60 + 25);
}
}
function drawStartMenu() {
textSize(24);
textAlign(CENTER, CENTER);
text("Clique para iniciar a degustação", width / 2, height / 2);
}
function drawDish() {
let dish = menu[currentDishIndex];
textSize(28);
textAlign(CENTER, CENTER);
text(dish.name, width / 2, height / 2);
}
function eatDish() {
// Simula o prato "entrando na boca"
eating = false;
nextDish();
}
function mousePressed() {
if (currentDishIndex === -1) {
currentDishIndex = 0;
}
}
function nextDish() {
currentDishIndex++;
if (currentDishIndex >= menu.length) {
currentDishIndex = -1;
alert("Degustação finalizada! Obrigado por participar.");
}
}