xxxxxxxxxx
69
// click and hold inside of the canvas to move the red ellipse
// release the mouse to stop the ellipse
// the closer the red ellipse lands to the yellow ellipse the more points you get
// holding the mouse down for less time also gets you more points
// the speed of the red ellipse is based off of your points
let start;
let end;
let duration;
let x_pos;
let score = 16;
function setup() {
createCanvas(400, 400);
x_pos = width/2;
}
function draw() {
background(220);
noStroke();
fill(235, 140, 52);
ellipse(width/2, height/2, 100, 100);
fill(235, 192, 52);
ellipse(width/2, height/2, 75, 75);
fill(235, 232, 52);
ellipse(width/2, height/2, 50, 50);
if (mouseIsPressed) {
fill(255, 0, 0, 200);
x_pos = map(sin(frameCount/score), -1, 1, 0, width);
ellipse(x_pos, height/2, 50, 50);
} else {
fill(235, 52, 216, 100);
ellipse(x_pos, height/2, 50, 50);
}
}
function mousePressed(){
start = Date.now();
}
function mouseReleased(){
end = Date.now();
duration = end - start;
score = calculatePoints();
console.log("score: " + score);
}
function calculatePoints(){
let timeBonus = 0;
if (duration <= 10000){
timeBonus = map(duration, 0, 10000, 25, 0);
}
let distance = dist(x_pos, height/2, width/2, height/2);
let distanceBonus = map(distance, 0, width/2, 25, 0);
let score = map(timeBonus + distanceBonus, 0, 50, 32, 4);
console.log("\nduration: " + duration);
console.log("distance: " + distance);
return score;
}