Hi all,
I’m trying to build a clock. The core idea is to have the actual time track the mouse behavior. As time passed, each past timestamp will get placed behind the current time, creating a visible trail of passed time. Where I’m struggling is that I want to trail of past times to always move towards a predefined endpoint while still tracking mouse behavior - like a draining effect. As of now (because my code is wrong) I can only get the trail to move towards the 0,0 position instead of the intended center of the window.
Does anyone how a clue what I’m doing wrong here? I’ve been contemplating implementing RADIANS and DEGREES but don’t know how I would do that.
Any help will be appreciated. Thanks!
//CODE
let passedTimes = [];
let currentTime = "";
let increaseFactor = 14;
let tSize = 48
let alphaDecrease = 90;
let maxDistance;
let omegaPointX;
let omegaPointY;
function setup(){
createCanvas(windowWidth,windowHeight);
}
function draw(){
let omegaPointX = windowWidth/2;
let omegaPointY = windowHeight/2;
background(240);
rect(omegaPointX, omegaPointY, 2,2)
strokeWeight(1)
fill(0);
calcTime();
displayCurrentTime();
displayPassedTimes();
}
//Calculate the time
function calcTime() {
let hr = hour();
let min = minute();
let sec = second();
let prevSec = sec;
const time = (hr < 10 ? "0" + hr : hr) + ":" +
(min < 10 ? "0" + min : min) + ":" +
(sec < 10 ? "0" + sec : sec );
//TODO: Update per second, not frame rate
if(frameCount % 60 == 0) {
currentTime = time;
passedTimes.unshift(time);
}
}
//Show current time
function displayCurrentTime(){
textAlign(CENTER);
textSize(tSize);
text(currentTime, mouseX, mouseY);
}
//Show trails of passed times
function displayPassedTimes(){
for(i = 0; i < passedTimes.length; i++){
fill(0, alphaDecrease-(i*1.6));
textSize(tSize-(i*1.2))
let increaseFactorX = map(mouseX, 0, windowWidth, 0, 24)
let increaseFactorY = map(mouseY, 0, windowHeight, 0, 24)
//Make each passed timestamp move towards the Omega point, while tracking the mouse position
text(passedTimes[i], mouseX-(i*increaseFactorX), mouseY-(i*increaseFactorY));
}
}