xxxxxxxxxx
193
let titles = [
"Artificial Intelligence",
"FIFA World Cup",
"Animals",
"Cryptocurrency",
"Economy",
"Education",
"Environment",
"Pharmaceuticals",
"Religion",
"Space Exploration"
]
let answer = "It is the demo that's fake. \nAll videos were televised. No video was fake.\n\n The more ridiculous our news appears to seem, \nthe harder it becomes for us to distinguish \nreal news from doctored videos.";
let revealAnswer = false;
let showStats = false;
let timerIndex = 0;
let timer;
let index = -1;
var stats = [];
function setup() {
createCanvas(windowWidth, windowHeight);
// fullscreen(true);
for (var i in titles) {
stats.push(new Stats(titles[i]));
}
timer = new Timer(35, 0);
noStroke();
textAlign(CENTER);
rectMode(CENTER);
}
function draw() {
background(255);
title(timerIndex, width / 2, height * 2 / 5);
// circularTimer(timer, width / 2, height * 2 / 5, 96, 96);
push();
translate(0, 50);
options();
pop();
if (timer.isTimeLeft()) {
timer.update();
} else {
timer.resetClock(millis());
console.log(timerIndex + " : " + index);
if (index >= 0) {
revealAnswer = true;
stats[timerIndex].addVote(index);
}
index = -1;
timerIndex++;
timerIndex %= titles.length;
}
if (revealAnswer) answerCard();
if (showStats) statsCard();
}
function rectangularTimer(theTimerObject, x, y, w, h) {
fill(100);
rect(x, y, w, h);
fill(255);
rect(x, y, w * theTimerObject.timeLeftPercentage, h);
}
function circularTimer(theTimerObject, x, y, w, h) {
fill(100);
ellipse(x, y, w, h);
fill(255);
arc(x, y, w, h, PI * 3 / 2, -(PI / 2 + PI * 2 * theTimerObject.timeLeftPercentage));
}
class Stats {
constructor(topic) {
this.topic = topic;
this.screenVotes = [0, 0, 0];
}
addVote(screenID) {
this.screenVotes[screenID]++;
}
totalVotes() {
return this.screenVotes[0] + this.screenVotes[1] + this.screenVotes[2];
}
}
class Timer {
constructor(seconds, startMillis) {
this.seconds = seconds;
this.startMillis = startMillis;
this.endMillis = this.startMillis + this.seconds * 1000;
}
update() {
this.timeLeft = int((this.endMillis - millis()) / 1000);
this.timeLeftPercentage = (((this.endMillis - millis()) / (this.seconds * 1000)));
}
isTimeLeft() {
if (this.timeLeftPercentage <= 0) {
return false;
} else {
return true;
}
}
resetClock(currTime) {
this.startMillis = currTime;
this.endMillis = this.startMillis + this.seconds * 1000;
this.update();
}
}
function title(id, x, y) {
fill(100);
textSize(32);
text("One of the screens' videos are fake and were not televised. \nCan you guess which one?", x, y - 120);
text("Current topic : " + titles[id], x, y + 120);
}
function options() {
for (i = 0; i < 3; i++) {
if (i == index) {
fill(100);
stroke(255);
rect(width * (i / 3) + width / 6, height * 2 / 3 - 12, 300, 96, 48); // magic number :(
fill(255);
} else {
fill(255);
stroke(100);
rect(width * (i / 3) + width / 6, height * 2 / 3 - 12, 300, 96, 48); // magic number :(
fill(100);
}
noStroke();
text("Screen " + (i + 1), width * (i / 3) + width / 6, height * 2 / 3);
}
if (index >= 0) {
fill(255);
stroke(100);
rect(width * (1 / 3) + width / 6, height * 5 / 6 - 12, 300, 96, 48); // magic number :(
fill(100);
text("Go", width * (1 / 3) + width / 6, height * 5 / 6);
}
noStroke();
}
function answerCard() {
push();
translate(0, 50);
background(255);
fill(255);
stroke(100);
rect(width * (1 / 3) + width / 6, height * 5 / 6 - 12, 300, 96, 48); // magic number :(
fill(100);
text("Oh...", width * (1 / 3) + width / 6, height * 5 / 6);
text(answer, width / 2, height / 3);
pop();
}
function statsCard() {
background(255);
fill(100);
for (var i in titles) {
text(stats[i].topic, width / 5, 200 + i * 40);
text(stats[i].screenVotes[0] + '\t' + stats[i].screenVotes[1] + '\t' + stats[i].screenVotes[2], width * 2 / 3, 200 + i * 40);
}
}
function mousePressed() {
let xValue = mouseX;
if (mouseY < 100) {
showStats = !showStats;
} else if (mouseY < height * 5 / 6) {
index = int(xValue / (width / 3));
} else {
revealAnswer = !revealAnswer;
if (revealAnswer == true) {
stats[timerIndex].addVote(index);
index = -1;
}
}
}
function keyReleased() {
if (key == ' ') {
showStats = !showStats;
} else if (key == 's' || key == 'S') {
saveCanvas('myCanvas', 'jpg');
}
}