xxxxxxxxxx
367
//Assets
var myFontBook;
var Title, Version, Instruction, SelectReg, SelDiscard, Regions, RegionsBDis, RegionAH, RegionBH, RegionCH, RegionDH, RegionEH;
var pics = [];
var i = 0;
//Color palette
/*
var color1 = '#0f1626';
var color2 = '#e9af28';
var color3 = '#ff533d';
var color4 = '#ab987a';
var color5 = '#f5f5f5';
var color6 = '#000000';
*/
var color1 = '#200605';
var color2 = '#fcb702';
var color3 = '#d51101';
var color4 = '#e35901';
var color5 = '#f7ead8';
var color6 = '#000000';
//Page titles
var line1, line2, line3, line4;
//Buttons
var homeb, instructionsb, regionbA, regionbB, regionbC, regionbD, regionbE, regionsb, overlayb, discardb, retainb, resetb;
//Counters
var selectedImg = 0;
var currentImg;
var discards = 0;
var discardsMin = 1;
var shufflesMax = 9;
var randColour;
//Result page
var resultMsg = "";
var splitString;
function preload() {
//Preload font
myFontBook = loadFont('Assets/Font/GothamRounded-Book.otf');
//Preload images
Title = loadImage('Assets/Images/01-Title-1.png');
Version = loadImage('Assets/Images/01-Version-1.png');
Instruction = loadImage('Assets/Images/02-Text-1.png');
SelectReg = loadImage('Assets/Images/03-Text-1.png');
SelDiscard = loadImage('Assets/Images/04-Text-1.png');
Regions = loadImage('Assets/Images/03-Regions.png');
RegionsBDis = loadImage('Assets/Images/03-Button-1-Dis.png');
RegionAH = loadImage('Assets/Images/03-Region-A-H.png');
RegionBH = loadImage('Assets/Images/03-Region-B-H.png');
RegionCH = loadImage('Assets/Images/03-Region-C-H.png');
RegionDH = loadImage('Assets/Images/03-Region-D-H.png');
RegionEH = loadImage('Assets/Images/03-Region-E-H.png');
for (i=1; i<10; i++) {
pics[i] = loadImage("Assets/Images/04-Pic-"+i+".png");
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(color1);
imageMode(CENTER);
textAlign(CENTER);
textFont(myFontBook);
textSize(20);
noStroke();
fill(color5);
drawScene1();
}
function draw() {
//NA
}
function drawScene1(){
background(color1);
homeb = createImg('Assets/Images/01-Button-1.png');
homeb.mousePressed(drawScene2);
homeb.position(width/2-112,height/2+160);
image(Title,width/2,height/2-25);
image(Version,width/2,height/2+290);
}
function drawScene2(){
background(color1);
homeb.hide();
instructionsb = createImg('Assets/Images/02-Button-1.png');
instructionsb.mousePressed(drawScene3);
instructionsb.position(width/2-74,height/2+170);
image(Instruction,width/2,height/2-280);
line2 = "Lorem ipsum dolor sit amet, consectetu /adipiscing elit, sed do eiusmod tempor /incididunt ut labore et dolore magna aliqua./Quis ipsum suspendisse ultrices gravida. /Risus commodo viverra maecenas/ accumsan lacus vel facilisis. /Lorem ipsum dolor sit amet, consectetur/ adipiscing elit, sed do eiusmod tempor /incididunt ut labore et dolore magna aliqua./ Quis ipsum suspendisse ultrices gravida. /Risus commodo viverra maecenas /accumsan lacus vel facilisis. "
splitString = split(line2, '/');
text(splitString[0], width / 2, height / 2-100-10);
text(splitString[1], width / 2, height / 2-75-10);
text(splitString[2], width / 2, height / 2-50-10);
text(splitString[3], width / 2, height / 2-25-10);
text(splitString[4], width / 2, height / 2-10);
text(splitString[5], width / 2, height / 2+25-10);
text(splitString[6], width / 2, height / 2+50-10);
text(splitString[7], width / 2, height / 2+75-10);
text(splitString[8], width / 2, height / 2+100-10);
}
function drawScene3(){
background(color1);
instructionsb.hide();
image(SelectReg,width/2,height/2-280);
imageMode(CORNER);
image(RegionsBDis,width/2-167.5,height/2+250);
//image(Regions,width/2,height/2);
regionbA = createImg('Assets/Images/03-Region-A.png');
regionbA.mousePressed(highlightA);
regionbA.position(width/2-162,height/2-202);
regionbB = createImg('Assets/Images/03-Region-B.png');
regionbB.mousePressed(highlightB);
regionbB.position(width/2-90.3,height/2-107.2);
regionbC = createImg('Assets/Images/03-Region-C.png');
regionbC.mousePressed(highlightC);
regionbC.position(width/2+61.4,height/2-93.9);
regionbD = createImg('Assets/Images/03-Region-D.png');
regionbD.mousePressed(highlightD);
regionbD.position(width/2-179.6,height/2-44);
regionbE = createImg('Assets/Images/03-Region-E.png');
regionbE.mousePressed(highlightE);
regionbE.position(width/2-117,height/2+33.35);
}
function highlightA() {
regionsb = createImg('Assets/Images/03-Button-1.png');
regionsb.mousePressed(drawScene4);
regionsb.position(width/2-167.5,height/2+250);
regionbA.hide();
regionbB.hide();
regionbC.hide();
regionbD.hide();
regionbE.hide();
imageMode(CENTER);
image(Regions,width/2,height/2);
imageMode(CORNER);
image(RegionAH,width/2-162,height/2-202);
}
function highlightB() {
regionsb = createImg('Assets/Images/03-Button-1.png');
regionsb.mousePressed(drawScene4);
regionsb.position(width/2-167.5,height/2+250);
regionbA.hide();
regionbB.hide();
regionbC.hide();
regionbD.hide();
regionbE.hide();
imageMode(CENTER);
image(Regions,width/2,height/2);
imageMode(CORNER);
image(RegionBH,width/2-90.3,height/2-107.2);
}
function highlightC() {
regionsb = createImg('Assets/Images/03-Button-1.png');
regionsb.mousePressed(drawScene4);
regionsb.position(width/2-167.5,height/2+250);
regionbA.hide();
regionbB.hide();
regionbC.hide();
regionbD.hide();
regionbE.hide();
imageMode(CENTER);
image(Regions,width/2,height/2);
imageMode(CORNER);
image(RegionCH,width/2+61.4,height/2-93.9);
}
function highlightD() {
regionsb = createImg('Assets/Images/03-Button-1.png');
regionsb.mousePressed(drawScene4);
regionsb.position(width/2-167.5,height/2+250);
regionbA.hide();
regionbB.hide();
regionbC.hide();
regionbD.hide();
regionbE.hide();
imageMode(CENTER);
image(Regions,width/2,height/2);
imageMode(CORNER);
image(RegionDH,width/2-179.6,height/2-44);
}
function highlightE() {
regionsb = createImg('Assets/Images/03-Button-1.png');
regionsb.mousePressed(drawScene4);
regionsb.position(width/2-167.5,height/2+250);
regionbA.hide();
regionbB.hide();
regionbC.hide();
regionbD.hide();
regionbE.hide();
imageMode(CENTER);
image(Regions,width/2,height/2);
imageMode(CORNER);
image(RegionEH,width/2-117,height/2+33.35);
}
function drawScene4() {
background(color1);
regionsb.hide();
/*
overlayb = createImg('Assets/Images/04-Overlay.png');
overlayb.mousePressed(drawScene5);
overlayb.position(width/2-211,height/2-375);
*/
imageMode(CENTER);
image(SelDiscard,width/2,height/2-280);
discardb = createImg('Assets/Images/04-Button-1.png');
discardb.mousePressed(discard);
discardb.position(width/2-67.5+100,height/2+280);
retainb = createImg('Assets/Images/04-Button-2.png');
retainb.mousePressed(retain);
retainb.position(width/2-67.5-100,height/2+280);
selectedImg = int(1, 9);
print(selectedImg);
currentImg = pics[selectedImg];
image(currentImg, width / 2, height / 2);
}
function drawScene5() {
background(color1);
discardb = createImg('Assets/Images/04-Button-1.png');
discardb.mousePressed(discard);
discardb.position(width/2-67.5+100,height/2+280);
retainb = createImg('Assets/Images/04-Button-2.png');
retainb.mousePressed(retain);
retainb.position(width/2-67.5-100,height/2+280);
image(SelDiscard,width/2,height/2-280);
print(selectedImg);
currentImg = pics[selectedImg];
image(currentImg, width / 2, height / 2);
}
function discard (){
discardb.hide();
retainb.hide();
selectedImg++;
discards ++;
if (selectedImg <= shufflesMax){
drawScene5();
} else {
resultPage();
}
}
function retain (){
discardb.hide();
retainb.hide();
selectedImg++;
if (selectedImg <= shufflesMax){
drawScene5();
} else {
resultPage();
}
}
function resultPage(){
background(color1);
resetb = createImg('Assets/Images/05-Button-1.png');
resetb.mousePressed(resetAll);
resetb.position(width/2-150.5,height-220);
if (discards > discardsMin) {
resultMsg = "Well done! You have/successfully discarded/" + discards + " out of " + shufflesMax + " people./This equates to " + round(discards/9*100) + "% of/the selected population.";
splitString = split(resultMsg, '/');
text(splitString[0], width / 2, height / 2-50-10);
text(splitString[1], width / 2, height / 2-25-10);
text(splitString[2], width / 2, height / 2-10);
text(splitString[3], width / 2, height / 2+25-10);
text(splitString[4], width / 2, height / 2+50-10);
} else {
resultMsg = "Too bad! You were/only able to discard/" + discards + " out of " + shufflesMax + " people./This equates to " + round(discards/9*100) + "% of/the selected population.";
splitString = split(resultMsg, '/');
text(splitString[0], width / 2, height / 2-50-10);
text(splitString[1], width / 2, height / 2-25-10);
text(splitString[2], width / 2, height / 2-10);
text(splitString[3], width / 2, height / 2+25-10);
text(splitString[4], width / 2, height / 2+50-10);
}
}
function resetAll (){
resetb.hide();
drawScene1();
}