Merge pull request #34 from ok2/codex/synchronize-analog-clock-with-current-cobie-time

This commit is contained in:
Kiyomichi Kosaka 2025-06-15 10:07:09 +02:00 committed by GitHub
commit aa2cca60b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 5 deletions

View File

@ -71,9 +71,7 @@
lastAngles[id] = angle;
}
function updateClock() {
const now = new Date();
const cob = toCobiets(now);
function renderClock(cob) {
// Use fractional progress within each unit so angles stay small
const xf = (cob % COBIE_UNITS.quantic) / COBIE_UNITS.quantic;
const qf = (cob % COBIE_UNITS.chronon) / COBIE_UNITS.chronon;
@ -87,10 +85,26 @@
rotateHand('handMegasequence', mf * 360);
}
function updateClock() {
renderClock(toCobiets(new Date()));
}
let intervalId = null;
function startClock() {
clearInterval(intervalId);
updateClock();
intervalId = setInterval(updateClock, 1000);
}
function showTime(cob) {
clearInterval(intervalId);
renderClock(cob);
}
function initClock() {
placeMarkers();
updateClock();
setInterval(updateClock, 1000);
startClock();
const clk = document.getElementById('clock');
if (clk) {
clk.addEventListener('click', () => {
@ -100,6 +114,10 @@
});
}
window.addEventListener('resize', placeMarkers);
window.CobieClock = {
start: startClock,
showTime
};
}
if (document.readyState === 'loading') {

View File

@ -640,6 +640,9 @@ function updateCalendar() {
clearInterval(updateInterval);
document.querySelector('.current-time').classList.add('manual');
updateCurrentTime();
if (window.CobieClock) {
window.CobieClock.showTime(manualCobiets);
}
});
})(cellCob + currentTime);
}
@ -737,6 +740,9 @@ function goToNow() {
clearInterval(updateInterval);
updateInterval = setInterval(updateCurrentTime, 1000);
document.querySelector('.current-time').classList.remove('manual');
if (window.CobieClock) {
window.CobieClock.start();
}
}
function enterEdit() {
@ -794,6 +800,9 @@ function commitInput() {
updateCurrentTime();
updateCalendar();
document.querySelector('.current-time').classList.add('manual');
if (window.CobieClock) {
window.CobieClock.showTime(manualCobiets);
}
}
// swap elements