mirror of
https://github.com/Kugelschieber/schnittfest.git
synced 2026-11-12 09:02:01 +01:00
26 lines
643 B
JavaScript
26 lines
643 B
JavaScript
const FPS = 25;
|
|
|
|
function pad(n) {
|
|
return String(n).padStart(2, "0");
|
|
}
|
|
|
|
export function initTimecode(el) {
|
|
const start = performance.now();
|
|
|
|
const tick = (now) => {
|
|
if (!el.isConnected) {
|
|
return;
|
|
}
|
|
|
|
const frames = Math.floor(((now - start) / 1000) * FPS);
|
|
const f = frames % FPS;
|
|
const s = Math.floor(frames / FPS) % 60;
|
|
const m = Math.floor(frames / (FPS * 60)) % 60;
|
|
const h = Math.floor(frames / (FPS * 3600));
|
|
el.textContent = `${pad(h)}:${pad(m)}:${pad(s)}:${pad(f)}`;
|
|
requestAnimationFrame(tick);
|
|
};
|
|
|
|
requestAnimationFrame(tick);
|
|
}
|