xxxxxxxxxx
135
let mouse;
let fakeX;
let fakeY;
let startX, startY;
let startTime;
let endStartTime;
let start;
let end;
let flash;
let pressed;
function setup() {
createCanvas(1000, 1000);
start = false;
end = false;
flash = 255;
pressed = false;
}
function draw() {
background(240);
// Schpeel
textSize(25);
text("This is a Predtictor. The screen below flashes green exactly 1.00000 seconds BEFORE you press the button. Try it.", 100, 100, 800);
// Screen
fill(flash, 255, flash);
stroke(0);
rect(100, 200, 800, 300);
// Button
noStroke()
fill(0);
rect(455, 555, 100, 50, 10);
stroke(0);
strokeWeight(3);
fill(150, 255, 150);
if (pressed) {
fill(255);
rect(455, 555, 100, 50, 10);
} else {
rect(450, 550, 100, 50, 10);
}
// Button text
noStroke();
fill(0);
if (pressed) {
text("Button", 468, 588);
} else {
text("Button", 463, 583);
}
if (start) {
let elapsed = millis() - startTime;
// Calculate progress as a value between 0 and 1
let prog = constrain(elapsed / 1000, 0, 1);
// Interpolate position
fakeX = lerp(startX, 500, prog);
fakeY = lerp(startY, 575, prog);
image(mouse, fakeX, fakeY, 14, 21);
// Stop the flashes
if (prog > 0.1) {
flash = 255;
}
// Start the second flash
if (prog > 0.2 && prog < 0.3) {
flash = 0;
}
// Check if the animation is complete
if (prog >= 1) {
start = false;
end = true;
endStartTime = millis();
startX = 500;
startY = 575;
pressed = true;
}
}
if (end) {
image(mouse, fakeX, fakeY, 14, 21);
let elapsed = millis() - endStartTime;
// Calculate progress as a value between 0 and 1
let prog = constrain(elapsed / 1000, 0, 1);
// Interpolate position
fakeX = lerp(startX, mouseX, prog);
fakeY = lerp(startY, mouseY, prog);
// Stops button press
if (prog > 0.2) {
pressed = false;
}
if (prog == 1) {
background(240);
text("See?", 100, 100);
noLoop();
cursor(ARROW);
}
}
if (mouseX > 400 && mouseX < 600 && mouseY > 475 && mouseY < 675 && !start && !end) {
buttonClick();
}
}
function preload() {
mouse = loadImage("cursor.png");
}
function buttonClick() {
flash = 0;
noCursor();
start = true;
startX = mouseX;
startY = mouseY;
startTime = millis();
}