diff --git a/fun.js b/fun.js index a3910099..8d3a974a 100644 --- a/fun.js +++ b/fun.js @@ -16,16 +16,18 @@ alert("fun yesss🎅🏼 you found santa congrats you won") function yourmom(){ alert("your mom still in testing") } - const fpsElem = document.querySelector("#fps"); - -let then = 0; -function render(now) { - now *= 0.001; // convert to seconds - const deltaTime = now - then; // compute time since last frame - then = now; // remember time for next frame - const fps = 1 / deltaTime; // compute frames per second - fpsElem.textContent = fps.toFixed(1); // update fps display - - requestAnimationFrame(render); -} -requestAnimationFrame(render); + var fps = document.getElementById("fps"); + var startTime = Date.now(); + var frame = 0; + + function tick() { + var time = Date.now(); + frame++; + if (time - startTime > 1000) { + fps.innerHTML = (frame / ((time - startTime) / 1000)).toFixed(1); + startTime = time; + frame = 0; + } + window.requestAnimationFrame(tick); + } + tick(); \ No newline at end of file diff --git a/index.html b/index.html index 6e1e7afd..b764a107 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ -