xxxxxxxxxx
365
let video;
let poseNet;
let pose;
let skeleton;
let img;
let chew, slurp, crunch, mmm;
let font, fontsize = 40;
var w = window.innerWidth;
var h = window.innerHeight;
var left;
var right;
var shouldExit;
var inIkea;
var shouldMeatballs;
var shouldMeatball;
var IkeaHatOn;
var inBirthday;
var shouldCake;
var shouldSlice;
var birthHatOn;
var inCoven;
var shouldCauldron;
var shouldIngredient;
var witchHatOn;
function onSoundLoadSuccess(e){
console.log("load sound success",e);
}
function onSoundLoadError(e){
console.log("load sound error",e);
}
function onSoundLoadProgress(e){
console.log("load sound progress",e);
}
function preload() {
soundFormats('mp3', 'ogg');
chew = loadSound("chewing.mp3",onSoundLoadSuccess,onSoundLoadError,onSoundLoadProgress);
slurp = loadSound("slurp.mp3",onSoundLoadSuccess,onSoundLoadError,onSoundLoadProgress);
mmm = loadSound("peter.mp3",onSoundLoadSuccess,onSoundLoadError,onSoundLoadProgress);
crunch = loadSound("crisp.mp3",onSoundLoadSuccess,onSoundLoadError,onSoundLoadProgress);
font = loadFont("font.ttf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
video=createCapture(VIDEO);
video.size(width, height);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on('pose', gotPoses);
textFont(font);
textSize(fontsize);
textAlign(CENTER, CENTER);
// body parts
head = loadImage('head.png');
leftHand = loadImage('hand.png');
rightHand = loadImage('other-hand.png');
// exit sign
exitSign = loadImage('exit.png');
// ikea
ikeaHat = loadImage('hats/Ikea-hat.png');
meatball = loadImage("food/meatball.png");
meatballs = loadImage("food/meatballs.png");
// birthday
birthdayHat = loadImage("hats/birthday-boy.png");
pieceOfCake = loadImage("food/cakePiece.png");
cake = loadImage("food/cake.png");
// coven
witchHat = loadImage("hats/witch-hat.png");
cauldron = loadImage("food/cauldron.png");
frogLeg = loadImage("food/frogLeg.png");
eyeball = loadImage("food/eyeball.png");
worms = loadImage("food/worms.png");
}
function gotPoses(poses) {
if (poses.length > 0) {
pose = poses[0].pose;
skeleton = poses[0].skeleton;
}
}
function modelLoaded() {
console.log('poseNet ready');
}
function words(str, y) {
translate(width, 0);
scale(-1, 1);
fill(255);
text(str, windowWidth*.50, y);
translate(width, 0);
scale(-1, 1);
}
function draw() {
translate(width, 0);
scale(-1, 1);
image(video, 0, 0, width, height);
background(0);
if (pose) {
let eyeR=pose.rightEye;
let eyeL=pose.leftEye;
let earR=pose.rightEar;
let earL=pose.leftEar;
let nose=pose.nose;
let shoulderR=pose.mirrorShoulder;
let shoulderL=pose.leftShoulder;
let elbowL=pose.leftElbow;
let elbowR=pose.rightElbow;
let wristL=pose.leftWrist;
let wristR=pose.rightWrist;
let hipR=pose.rightHip;
let hipL=pose.leftHip;
let kneeR=pose.rightKnee;
let kneeL=pose.leftKnee;
let ankleR=pose.rightAnkle;
let ankleL=pose.leftAnkle;
let d=dist(eyeR.x, eyeR.y, eyeL.x, eyeL.y)*1.4;
let handL = dist(wristL.x, wristL.y, elbowL.x, elbowL.y)*1.2;
let handR = dist(wristR.x, wristR.y, elbowR.x, elbowR.y)*1.2;
fill(255,0,0);
imageMode(CENTER);
// CANVAS: 640X480
// IKEA
if((wristL.y < windowHeight*.25 && wristL.x > windowWidth*.85)&&(((!inIkea)&&(!inBirthday)))&&(!inCoven)){
inIkea = true;
}
if((inIkea) && (wristR.x < windowWidth*.25 && wristR.y < windowHeight*.25)){
shouldMeatball = false;
inIkea = false;
}
// BIRTHDAY
if((wristL.x > windowWidth*.85&&((wristL.y > windowHeight*.6)&&(wristL.y < windowHeight*.8)))&&(((!inIkea)&&(!inBirthday)))&&(!inCoven)) {
inBirthday = true;
}
if((inBirthday) && (wristR.x < windowWidth*.25 && wristR.y < windowHeight*.25)){
shouldSlice = false;
inBirthday = false;
}
// COVEN
// 0, windowHeight*.9
if((wristR.x < windowWidth*.2&&((wristR.y > windowHeight*.6)&&(wristR.y < windowHeight*.8)))&&(((!inIkea)&&(!inBirthday)))&&(!inCoven)) {
inCoven = true;
}
if((inCoven) && (wristR.x < windowWidth*.25 && wristR.y < windowHeight*.25)){
shouldIngredient = false;
inCoven = false;
}
if(inIkea) {
shouldExit = true;
IkeaHatOn = true;
shouldMeatballs = true;
words('welcome to ikea!', windowHeight*.02);
words('eat some meatballs.', windowHeight*.08);
// pick up meatballs
if((wristL.y>(windowHeight*.75-windowWidth*.03)&&wristL.y<(windowHeight*.75+windowWidth*.03))&&(wristL.x>(windowWidth*.5-windowWidth*.03)&&wristL.x<(windowWidth*.5+windowWidth*.03))) {
shouldMeatball = true;
left = true;
}
if((wristR.y>(windowHeight*.75-windowWidth*.03)&&wristR.y<(windowHeight*.75+windowWidth*.03))&&(wristR.x>(windowWidth*.5-windowWidth*.03)&&wristR.x<(windowWidth*.5+windowWidth*.03))) {
shouldMeatball = true;
right = true;
}
// eat meatballs
if(shouldMeatball) {
if(right) {
if(dist((wristR.x+(handR*.15)), (wristR.y-(handR*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
right = false;
chew.play();
}
}
if(left) {
if(dist((wristL.x-(handL*.15)), (wristL.y-(handL*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
left = false;
chew.play();
}
}
}
}
else if(inBirthday) {
shouldExit = true;
birthHatOn = true;
shouldCake = true;
words('happy birthday!', windowHeight*.02);
words('enjoy your cake!', windowHeight*.08);
// pickup cake
if((wristL.y>(windowHeight*.75-windowWidth*.1)&&wristL.y<(windowHeight*.75+windowWidth*.1))&&(wristL.x>(windowWidth*.5-windowWidth*.08)&&wristL.x<(windowWidth*.5+windowWidth*.08))) {
shouldSlice = true;
left = true;
}
if((wristR.y>(windowHeight*.75-windowWidth*.09)&&wristR.y<(windowHeight*.75+windowWidth*.09))&&(wristR.x>(windowWidth*.5-windowWidth*.09)&&wristR.x<(windowWidth*.5+windowWidth*.09))) {
shouldSlice = true;
right = true;
}
// eat cake
if(shouldSlice) {
if(right) {
if(dist((wristR.x+(handR*.15)), (wristR.y-(handR*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
right = false;
mmm.play();
}
}
if(left) {
if(dist((wristL.x-(handL*.15)), (wristL.y-(handL*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
left = false;
mmm.play();
}
}
}
}
else if(inCoven) {
shouldExit = true;
witchHatOn = true;
shouldCauldron = true;
words('that cauldron smells delicious!', windowHeight*.02);
words("i wonder what's in it?", windowHeight*.08);
// pick up ingredients
if((wristL.y>(windowHeight*.75-windowWidth*.1)&&wristL.y<(windowHeight*.75+windowWidth*.1))&&(wristL.x>(windowWidth*.5-windowWidth*.08)&&wristL.x<(windowWidth*.5+windowWidth*.08))) {
shouldIngredient = true;
left = true;
}
if((wristR.y>(windowHeight*.75-windowWidth*.1)&&wristR.y<(windowHeight*.75+windowWidth*.1))&&(wristR.x>(windowWidth*.5-windowWidth*.08)&&wristR.x<(windowWidth*.5+windowWidth*.08))) {
shouldIngredient = true;
right = true;
}
// eat ingredient
if(shouldIngredient) {
if(right) {
if(dist((wristR.x+(handR*.15)), (wristR.y-(handR*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
right = false;
slurp.play();
}
}
if(left) {
if(dist((wristL.x-(handL*.15)), (wristL.y-(handL*.25)), pose.nose.x, pose.nose.y+(d/2))<(d/2)) {
left = false;
crunch.play();
}
}
}
}
else {
words('grab a hat', windowHeight*.08);
shouldExit = false;
left = false;
right = false;
IkeaHatOn = false;
shouldMeatballs = false;
shouldMeatball = false;
birthHatOn = false;
shouldCake = false;
shouldSlice = false;
witchHatOn = false;
shouldCauldron = false;
shouldingredient = false;
let ikeaDist = dist(wristL.x, wristL.y, windowWidth*.9, windowHeight*.05);
image(ikeaHat, windowWidth*.9, windowHeight*.2, min((windowWidth*.25)*100/ikeaDist, windowWidth*.25), min((windowHeight*.3)*100/ikeaDist, windowHeight*.3));
let birthDist = dist(wristL.x, wristL.y, windowWidth*.9, windowHeight*.8);
image(birthdayHat, windowWidth*.9, windowHeight*.8, min((windowWidth*.25)*100/birthDist, windowWidth*.25), min((windowWidth*.25)*100/birthDist, windowWidth*.25));
let witchDist = dist(wristR.x, wristR.y, windowWidth*.1, windowHeight*.9);
image(witchHat, windowWidth*.1, windowHeight*.8, min((windowWidth*.25)*100/witchDist, windowWidth*.25), min((windowWidth*.25)*100/witchDist, windowWidth*.25));
}
imageMode(CENTER)
angleMode(DEGREES)
// Body
image(head, pose.nose.x, pose.nose.y, d*2,d*2);
image(rightHand, wristR.x, wristR.y, handR*.35, handR*.7);
image(leftHand, wristL.x, wristL.y, handL*.35, handL*.7);
// Image Bools
if(shouldExit) {
image(exitSign, windowWidth*.2, windowHeight*.2, 80, 50);
}
// ikea
if(IkeaHatOn) {
image(ikeaHat, pose.nose.x, pose.nose.y-d,d*2.5, d*1.3);
}
if(shouldMeatballs){
image(meatballs, windowWidth*.5, windowHeight*.75, windowWidth*.2, windowWidth*.2);
}
if(shouldMeatball){
if(right) {
image(meatball, wristR.x+handR*.15, wristR.y-handR*.25, windowWidth*.1, windowWidth*.1);
}
if(left) {
image(meatball, wristL.x+handL*.15, wristL.y-handL*.25, windowWidth*.1, windowWidth*.1);
}
}
// birthday
if(birthHatOn) {
image(birthdayHat, pose.nose.x, pose.nose.y-d,d*2.75, d*2.75);
}
if(shouldCake){
image(cake, windowWidth*.5, windowHeight*.75, windowWidth*.18, windowWidth*.18);
}
if(shouldSlice){
if(right) {
image(pieceOfCake, wristR.x+handR*.15, wristR.y-handR*.25, windowWidth*.1, windowWidth*.1);
}
if(left) {
image(pieceOfCake, wristL.x+handL*.15, wristL.y-handL*.25, windowWidth*.08, windowWidth*.08);
}
}
// coven
if(witchHatOn) {
image(witchHat, pose.nose.x, pose.nose.y-d,d*2.75, d*2.75);
}
if(shouldCauldron){
image(cauldron, windowWidth*.5, windowHeight*.75, windowWidth*.15, windowWidth*.17);
}
if(shouldIngredient) {
if(right) {
image(eyeball, wristR.x+handR*.15, wristR.y-handR*.25, windowWidth*.05, windowWidth*.05);
}
if(left) {
image(frogLeg, wristL.x+handL*.15, wristL.y-handL*.25, windowWidth*.1, windowWidth*.1);
}
}
}
}