xxxxxxxxxx
105
let img;
let emotions;
let table;
let firstsentence;
let finalsecondstring;
function preload(){
img = loadImage('Convo.png')
table = loadTable('Emotions.csv', 'csv', 'header');
}
function setup() {
let sizing = 600;
createCanvas(sizing, sizing); //works for any squre canvas
let openers = ["True, " , "Right!, " , "Agreed, " , "Same, ", "Fax, " , "Relatable, " , "Yeah, " , "I see, "]; //additions to the second speech
let labels = []; //emotion number 0-5
let texts = [];
let sadness = [];
let joy = [];
let love = [];
let anger = [];
let fear = [];
let surprise = [];
let rows = table.getRows();
for (let r = 0; r < rows.length; r++) {
labels.push(rows[r].get('label')); //emotion numbers array
texts.push(rows[r].get('text')); //text array
if (rows[r].get('label')=='0'){
sadness.push(rows[r].get('text')); //append sad text only to sadness array, do the same for other emotions
}
else if (rows[r].get('label')=='1'){
joy.push(rows[r].get('text'));
}
else if (rows[r].get('label')=='2'){
love.push(rows[r].get('text'));
}
else if (rows[r].get('label')=='3'){
anger.push(rows[r].get('text'));
}
else if (rows[r].get('label')=='4'){
fear.push(rows[r].get('text'));
}
else {
surprise.push(rows[r].get('text'));
}
}
let firstnum = Math.round(random(0, 199)); //choose first sentence at random
print(firstnum);
let row;
let secondsentence;
firstsentence = texts[firstnum]; //first text
let emotionnum = labels[firstnum];
//match text to emotion and get another random sentance of same emtion
if (emotionnum == '0'){
let secondRand = Math.round(random(0, sadness.length));
secondsentence = sadness[secondRand];
}
else if (emotionnum == '1'){
let secondRand = Math.round(random(0, joy.length));
secondsentence = joy[secondRand];
}
else if (emotionnum == '2'){
let secondRand = Math.round(random(0, love.length));
secondsentence = love[secondRand];
}
else if (emotionnum == '3'){
let secondRand = Math.round(random(0, anger.length));
secondsentence = anger[secondRand];
}
else if (emotionnum == '4'){
let secondRand = Math.round(random(0, fear.length));
secondsentence = fear[secondRand];
}
else if (emotionnum == '5'){
let secondRand = Math.round(random(0, surprise.length));
secondsentence = surprise[secondRand];
}
let randOpener = Math.round(random(0, openers.length));
finalsecondstring = openers[randOpener] + secondsentence; //second text
}
function draw() {
background(220);
imageMode(CENTER);
image(img, width/2, height/2, width, height);
strokeWeight(1);
textSize(width*0.02);
//rect and circle used for speech indication
rect(width*1.6/100, width*1.6/100, width/3, width*0.25);
circle(width*0.183, width/3, width*0.0083);
circle(width*0.158, width*0.316, width*0.0166);
circle(width*0.133, width*0.286, width*0.033);
text(firstsentence, width*0.016, width*0.016, width/3, width*0.25); //first speech
circle(width*0.816, width/3, width*0.0083);
circle(width*0.841, width*0.316, width*0.016);
circle(width*0.866, width*0.286, width*0.033);
rect(width*0.65, width*0.016, width/3, width*0.25);
text(finalsecondstring, width*0.65, width*0.0166, width/3, width*0.25); //second speech
}