xxxxxxxxxx
298
let jsonFile;
let dataPoints = [];
let sentence1 = ['Life','is','A','Struggle'];
let word;
let ts = 50;
let x = 100;
let y = 100;
let x3 = 300;
let y3 = 300;
let speed = 1;
let r = 0;
let facai;
let sceneNum = 0;
let buttonmusic;
let song;
let huahua;
let buttonlook;
let buttondelete;
let word3;
let sentence3 = ['Second','Minute','Hour','Day'];
function preload(){
jsonFile = loadJSON('emotiondata.json');
bgm1 = loadSound('renjiashige.mp3');
song = loadSound('haoyunlai.mp3');
huahua = loadImage('huahua.gif');
bottle = loadImage('bottle.png');
depression = loadImage('depression.png');
fu = loadImage('fu.gif');
}
function setup() {
createCanvas(600, 600);
rectMode(CENTER);
angleMode(DEGREES);
imageMode(CENTER);
textAlign(CENTER,CENTER);
buttonmusic = createButton('music on');
buttonlook = createButton('have a look');
buttondelete = createButton('delete these negative emotions');
bgm1.setVolume(0.4);
song.setVolume(0.1);
bgm1.play();
for ( let i in jsonFile ) {
let currentItem =
{
x: random(100,500),
y: random(100,500),
durationx: jsonFile[i].timehr,
durationy: jsonFile[i].timemin,
notes: jsonFile[i].notes,
feeling: jsonFile[i].feeling
};
dataPoints.push(currentItem);
}
scene1();
scene3();
}
function draw() {
background(255);
switch(sceneNum){
case 0:
background(0);
image(depression,300,300);
push();
translate(x,y);
x = x + speed;
rotate(r);
r = r + speed;
textSize(ts);
fill(255);
text(word, 0, 0);
pop();
push();
textSize(36);
fill(255);
text('My Negative Emotions Container',300,400);
pop();
image(bottle,310,460);
buttonmusic.hide();
buttonlook.show();
buttonlook.position(270,500);
buttonlook.style("background-color", "#99ccff");
buttonlook.mousePressed(changescene);
buttondelete.hide();
break;
case 1:
background(0);
for( let i = 0; i < dataPoints.length; i++){
if(dataPoints[i].feeling == "hungry"){
fill(102,255,102);
}else if(dataPoints[i].feeling == "frustrated"){
fill(128,229,255);
}else if(dataPoints[i].feeling == "tired"){
fill(221,153,255);
}else if(dataPoints[i].feeling == "anxious"){
fill(255,153,51);
}else if(dataPoints[i].feeling == "ashamed"){
fill(255,128,170);
}
noStroke();
rect(dataPoints[i].x, dataPoints[i].y, dataPoints[i].durationx,dataPoints[i].durationy);
if(dist(mouseX, mouseY, dataPoints[i].x,dataPoints[i].y) < 15){
fill('white');
textSize(18);
text(dataPoints[i].notes, dataPoints[i].x, dataPoints[i].y);
}
}
push();
fill(102,255,102);
textSize(20);
text('hungry',50,540);
pop();
push();
fill(128,229,255);
textSize(20);
text('frustrated',170,540);
pop();
push();
fill(221,153,255);
textSize(20);
text('tired',290,540);
pop();
push();
fill(255,153,51);
textSize(20);
text('anxious',400,540);
pop();
push();
fill(255,128,170);
textSize(20);
text('ashamed',540,540);
pop();
push();
buttonmusic.hide();
buttonlook.hide();
buttondelete.show();
buttondelete.style("background-color", "#000000");
buttondelete.style("color", "#ff0000");
buttondelete.position(210,570);
buttondelete.mousePressed(changescene);
pop();
break;
case 2:
buttonmusic.show();
buttonmusic.position(266,550);
buttonmusic.style("background-color", "#e6ccff");
buttonlook.hide();
buttondelete.hide();
buttonmusic.mousePressed(togglePlaying);
background(255,255,204);
push();
translate(x3,y3);
x3 = x3 + speed;
// rotate(r);
// r = r + speed;
fill(255,153,204);
textSize(ts);
text(word3, 0, 0);
pop();
push();
image(huahua,300,100);
textSize(36);
fill(230,0,115);
text('Happy Every',200,300);
facai = createImg('facai.gif');
facai.position(320,380);
pop();
buttonmusic.style("background-color", "#ff3333");
image(fu,100,500,100,100);
bgm1.pause();
break;
}
}
function scene1_0(){
word = sentence1[0];
ts = 50;
speed = 3;
}
function scene1_1(){
word = sentence1[1];
ts = 50;
speed = -3;
}
function scene1_2(){
word = sentence1[2];
ts = 40;
speed = 3;
}
function scene1_3(){
word = sentence1[3];
ts =70;
speed = -3;
}
function scene3_0(){
word3 = sentence3[0];
ts = 50;
speed = 0.9;
}
function scene3_1(){
word3 = sentence3[1];
ts = 50;
speed = -1.1;
}
function scene3_2(){
word3 = sentence3[2];
ts = 40;
speed = 0.9;
}
function scene3_3(){
word3 = sentence3[3];
ts =70;
speed = -1.2;
}
function scene1(){
setTimeout(scene1_0,1000);
setTimeout(scene1_1,3000);
setTimeout(scene1_2,5000);
setTimeout(scene1_3,7000);
}
function scene3(){
setInterval(scene3_0,1000);
setInterval(scene3_1,3000);
setInterval(scene3_2,5000);
setInterval(scene3_3,7000);
}
function togglePlaying(){
if(!song.isPlaying()){
song.play();
buttonmusic.html('music off');
}else{
song.pause();
buttonmusic.html('music on');
}
}
function changescene(){
sceneNum++
}