xxxxxxxxxx
479
let sceneNum = 0;
let img;
//scene#1
let guys = [];
let speed = 0
let faces = [];
let guyName = ['Albert Ridley','Alex Frost','Jody Allman','Finnian Bate','Cassian Bloggs','Connor Wharton','Yash Lister','Levi Parkes','Blaine Gough ','Hashim Small'];
let guyBeh = ['He is late for the first date','He asks very personal questions about income','He picks the restaurant before asking your opinion','He constantly watches his phone','He holds your hand without asking','He keeps talking about himself','He talks dirty languages','He sends me nude pictures without asking','He peeks at my screen sometimes'];
//scene#2
let heads = [];
let tops = [];
let bottoms = [];
let head1 = [];
let top1 = [];
let bottom1 = [];
//scene#5
let webcam;
let tracker;
let features;
function preload() {
let f1 = loadImage('f1.png');
let f2 = loadImage('f2.png');
let f3 = loadImage('f3.png');
let f4 = loadImage('f4.png');
let f5 = loadImage('f5.png');
let f6 = loadImage('f6.png');
let f7 = loadImage('f7.png');
let f8 = loadImage('f8.png');
let f9 = loadImage('f9.png');
let h1 = loadImage('h1.png');
let h2 = loadImage('h2.png');
let h3 = loadImage('h3.png');
let h4 = loadImage('h4.png');
let t1 = loadImage('t1.png');
let t2 = loadImage('t2.png');
let t3 = loadImage('t3.png');
let t4 = loadImage('t4.png');
let d1 = loadImage('d1.png');
let d2 = loadImage('d2.png');
let d3 = loadImage('d3.png');
let d4 = loadImage('d4.png');
faces = [f1, f2,f3,f4,f5,f6,f7,f8,f9];
heads = [h1,h2,h3,h4];
tops = [t1,t2,t3,t4];
bottoms = [d1,d2,d3,d4];
let smile1 = loadImage('smile.png');
}
function setup() {
createCanvas(400, 400);
background(100);
textFont('Georgia');
//Scene #3
for (let i = 0; i < 20; i++){
let face = random(faces)
guys[i] = new Guy(random(0,400),random(100,400),60,face);
}
//Scene #4
for (let i = 0; i < 10; i++){
let ranhead = random(heads)
head1[i] = new Head(200,70, 80, ranhead);
}
for (let i = 0; i < 10; i++){
let rantop = random(tops)
top1[i] = new Top(200,180, 80, rantop);
}
for (let i = 0; i < 10; i++){
let ranbottom = random(bottoms)
bottom1[i] = new Bottom(200,300, 80, ranbottom);
}
//Scene #6
webcam = createCapture(VIDEO);
webcam.size(width,height);
webcam.elt.setAttribute('playsinline', '');
webcam.hide();
tracker = new clm.tracker();
tracker.init();
tracker.start(webcam.elt);
smile1 = loadImage('smile.png');
}
function draw() {
switch (sceneNum) {
case 0:
console.log("scene 0");
background(100);
noStroke()
textSize(40);
textAlign(CENTER);
fill(255)
text("510000",200,120);
fill(50);
ellipse(200,200,130,80);
fill(255);
textSize(32)
text("PLAY",200,210);
break;
case 1:
console.log("scene 1");
background(100);
textSize(18);
textAlign(CENTER);
fill(255);
text('"I used to be crazy about dating...',200,130);
text('at 510000 where I lived during highschool...',200,160);
text('I am too young to understand',200,190);
text('what dating really means to me."',200,220);
fill(50);
ellipse(300,300,100,40);
fill(255);
textSize(20)
text('Next',300,305);
break;
case 2:
background(100);
console.log("scene 2");
textSize(32);
textAlign(CENTER);
text("Ask Him Out",200,40)
textSize(14);
text("Pick a guy and CLICK",200,65)
fill(255)
for (let i = 0; i < 20; i++){
guys[i].body();
guys[i].move();
}
break;
case 3:
console.log("scene 3");
// guyText();
// loop();
fill(50);
ellipse(130,250,90,40);
ellipse(270,250,90,40);
fill(255);
text('OKAY',270,255);
text('NOT OKAY',130,255)
break;
case 4:
console.log("scene 4");
background(100)
textAlign(CENTER);
fill(255);
textSize(14);
text("Move your mouse to change appearances",200,40)
fill(50);
ellipse(320,350,100,50);
fill(255);
text("I am Ready!",320,355)
// fill(0);
for (let i = 0; i < 10; i++){
head1[i].body()
head1[i].click()
// if(heads[i].img == 'f1.png'){
// fill(255,0,0);
// ellipse(200,200,100);
// }
}
for (let i = 0; i < 10; i++){
top1[i].body()
top1[i].click()
// bodies[i].match()
}
for (let i = 0; i < 10; i++){
bottom1[i].body()
bottom1[i].click()
}
break;
case 5:
console.log('scene 5');
background(100);
textSize(14);
textAlign(CENTER);
fill(255);
text('"I tried to appeal them, but they never seem to notice',200,130);
text('I hate my fat belly and ugly nose. ',200,160);
text('But they are part of me which I should embrace. ',200,190);
text('I am tired of not being respected by guys',200,220);
text('I need changes, and love myself..."',200,250);
fill(50);
ellipse(300,300,100,40);
fill(255);
textSize(20)
text('Next',300,305);
break;
case 6:
console.log('scene 6');
background(100);
textAlign(CENTER);
fill(255);
textSize(20);
text("SMILE to win the game!",200,40)
// imageMode(CENTER);
image(webcam,320,310);
// image(smile1,200,200)
features = tracker.getCurrentPosition();
//face filter
//smile dectection
if (features.length > 0) {
// let chin = createVector(features[7][0], features[7][1]);
let mouthMid = createVector(features[57][0], features[57][1]);
let mouthLeft = createVector(features[44][0], features[44][1]);
let mouthRight = createVector(features[50][0], features[50][1]);
let facesize1 = createVector(features[33][0],features[33][1]);
let facesize2 = createVector(features[62][0],features[62][1]);
// let mouthMiddle = createVector(features[53][0], features[53][1]);
let smile = mouthLeft.dist(mouthMid)/facesize1.dist(facesize2) + mouthRight.dist(mouthMid)/facesize1.dist(facesize2)
print(smile); // shows the distance between mouthLeft and mouthRight
// if (smile > 8) {
// let smile1 = loadImage('smile.png')
// fill(255,0,0)
// image(smile1,200,200)
// // ellipse (200,200,50)
// }
// // smile bar
// rect(20, 20, smile * 3, 20);
// }
// let smile1 = loadImage('smile.png')
if(smile <= 1.4){
image(smile1,features[60][0], features[60][1], features[50][0]-features[44][0] + smile*100 , features[53][1]-features[47][1] + smile*50 );
} else if (smile > 1.4) {
background(255);
for(let b = 0; b<100; b++){
image (smile1,features[60][0], features[60][1],features[50][0]-features[44][0] + b*4 , features[53][1]-features[47][1] + b*2 )}
sceneNum++;
}
}
break;
case 7:
// background(220);
console.log('scene 7');
// background(255,100,100)
textAlign(CENTER);
fill(255,100,100);
textSize(40);
text("YOU WIN!!",200,120);
fill(50);
ellipse(200,200,100,40);
fill(255);
textSize(18)
text('Play Again',200,204);
break;
}
}
function mousePressed(){
if(sceneNum == 0){
if(mouseX > 135 && mouseX < 265 && mouseY > 160 && mouseY < 240){
sceneNum++
}
}
else if(sceneNum == 1){
if(mouseX > 250 && mouseX < 350 && mouseY > 280 && mouseY < 320){
sceneNum++
}
}
else if( sceneNum == 2) {
// // guys[i].click1()
for (let i = 0; i < 20; i++){
let d = dist(mouseX, mouseY, guys[i].x, guys[i].y);
if (d < 30) {
sceneNum = sceneNum + 1
noStroke();
fill(255);
rect(10,100,380,200,20);
fill(0);
textSize(14);
let rName = random(guyName);
let rBeh = random(guyBeh);
let gText1 = '"Hey, my name is '+ rName +'."'
let gText2 = rBeh + '.';
text(gText1,200,150);
text(gText2,200,200);
}}
}
else if (sceneNum == 3) {
if (mouseX < 180 && mouseX > 80 && mouseY < 280 && mouseY > 220){
sceneNum = sceneNum - 1
} else if (mouseX < 320 && mouseX > 220 && mouseY < 280 && mouseY > 220){
sceneNum++
}
}
else if (sceneNum == 4) {
//320,350,100,50
if (mouseX > 270 && mouseX < 370 && mouseY > 325 && mouseY < 375 ){
sceneNum++
}
}
else if (sceneNum == 5) {
if (mouseX > 250 && mouseX < 350 && mouseY > 280 && mouseY < 320) {
sceneNum++
}
}
else if(sceneNum == 7){
if(mouseX > 150 && mouseX < 250 && mouseY > 180 && mouseY < 240){
sceneNum = 0
}
}
}
//SCENE #3
class Guy {
constructor(x,y,r,img) {
this.x = x;
this.y = y;
this.r = r;
this.face = img;
}
body() {
noStroke()
// let ranFace = random(faces);
imageMode(CENTER)
image(this.face, this.x, this.y, 60, 60);
// ellipse(this.x,this.y,60,60)
}
move() {
this.x = this.x + speed
if(this.x <= 100 && this.x >= -50){
speed = random(0,1.5)
}
if(this.x >= 300 && this.x <= 400){
speed = -random(0,1.5)
}
}
}
// SCENE #4
class Head {
constructor(x,y,r,img) {
this.x = x;
this.y = y;
this.r = r;
this.head = img;
}
body() {
imageMode(CENTER)
// background(100)
fill(100)
rect(120,55,140,80);
image(this.head, this.x, this.y, 350,120 );
}
click() {
if (mouseX < this.x+60 && mouseX > this.x-60 && mouseY < this.y+60 && mouseY > this.y-60){
this.head = random(heads)
}
}
}
class Top {
constructor(x,y,r,img) {
this.x = x;
this.y = y;
this.r = r;
this.top = img;
}
body() {
imageMode(CENTER)
// background(100);
fill(100)
rect(115,130,140,150);
image(this.top, this.x, this.y, 320, 100);
}
click() {
if (mouseX < this.x+60 && mouseX > this.x-60 && mouseY < this.y+60 && mouseY > this.y-60){
this.top = random(tops)
}
}
}
class Bottom {
constructor(x,y,r,img) {
this.x = x;
this.y = y;
this.r = r;
this.bottom = img;
}
body() {
imageMode(CENTER)
// background(100);
fill(100)
rect(100,225,150,200);
image(this.bottom, this.x, this.y, 350, 150);
}
click() {
if (mouseX < this.x+60 && mouseX > this.x-60 && mouseY < this.y+60 && mouseY > this.y-60){
this.bottom = random(bottoms)
}
}
}