xxxxxxxxxx
118
let state = "gathering";
let forwards = true;
let speed = 0.01;
let max = 1.2;
let min = 1;
let counter = min;
let mugwort;
let treeofheaven;
let purslane;
let purslaneClicks = 0;
let treeofheavenClicks = 0;
let mugwortClicks = 0;
function preload() {
mugwort = loadImage("mugwort.png");
purslane = loadImage("purslane.png");
treeofheaven = loadImage("treeofheaven.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
imageMode(CENTER);
textAlign(CENTER);
textSize(20);
frameRate(10);
}
function draw() {
background(220);
/* If statement for different states */
if (state == "gathering") {
/* Animation code */
if (forwards) {
counter = counter + speed;
if (counter > max) {
forwards = false;
}
} else {
counter = counter - speed;
if (counter < min) {
forwards = true;
}
}
text("click a plant to forage until \ntincture is complete", width / 2, height / 2);
image(purslane, 100, 100, 100 * counter, 120 * counter);
image(mugwort, width - 100, height - 100, 100 * counter, 150 * counter);
image(treeofheaven, width - 100, 100, 100 * counter, 150 * counter);
text("purslane:" + purslaneClicks, 100, height - 100);
text("mugwort:" + mugwortClicks, 100, height - 75);
text("tree of heaven:" + treeofheavenClicks, 100, height - 50);
}else if(state == "results"){
background("bisque")
tint(200,255,100)
let largest = Math.max(treeofheavenClicks, mugwortClicks, purslaneClicks);
if(largest == treeofheavenClicks){
image(treeofheaven, width/2,height/2, 100,100)
text("you are resilient", width/2, height/2)
}else if(largest == mugwortClicks){
image(mugwort, width/2,height/2, 100,100)
text("you are in touch with your intuition", width/2, height/2)
}else{
image(purslane, width/2,height/2, 100,100)
text("you are resourceful", width/2, height/2)
}
text("return",width/2,height/1.2)
}
}
function mousePressed(){
if(state == "gathering"){
if(dist(mouseX, mouseY, 100, 100) < 50){
purslaneClicks = purslaneClicks + 1;
}
if(dist(mouseX, mouseY, width - 100, 100) < 50){
treeofheavenClicks = treeofheavenClicks + 1;
}
if(dist(mouseX, mouseY, width - 100, height - 100) < 50){
mugwortClicks = mugwortClicks + 1;
}
if(mugwortClicks + treeofheavenClicks + purslaneClicks == 10){
state = "results"
}
}else if(state == "results"){
if(dist(mouseX, mouseY, width/2,height/1.2) < 50){
mugwortClicks = 0
treeofheavenClicks = 0
purslaneClicks = 0
state = "gathering"
}
}
}