Skip to content

Commit bc5921a

Browse files
committed
html: Add second test page
1 parent 01f12fd commit bc5921a

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

html/raf_test.html

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<html>
2+
<head>
3+
<title>RAF Test Sample</title>
4+
<style>
5+
body {
6+
overflow: hidden;
7+
position: absolute;
8+
width: 100%;
9+
height: 100%;
10+
display: flex;
11+
align-items: center;
12+
justify-content: center;
13+
}
14+
15+
.wrapper {
16+
width: 70%;
17+
display: flex;
18+
flex-direction: column;
19+
gap: 1rem;
20+
justify-content: center;
21+
align-items: center;
22+
background-color: white;
23+
}
24+
25+
.container {
26+
width: 100%;
27+
text-align: center;
28+
font-family: monospace, monospace;
29+
font-size: 8vw;
30+
font-weight: bold;
31+
padding: 1rem;
32+
}
33+
</style>
34+
<script language="JavaScript">
35+
let frameNum = 0; // s
36+
let fps = 0;
37+
let t = undefined;
38+
let T = 0;
39+
40+
let text = undefined;
41+
42+
function alphaFilter(prevEst, value, alpha) {
43+
return prevEst + alpha * (value - prevEst);
44+
}
45+
46+
function animate(msg) {
47+
let dt = 0;
48+
if (t !== undefined) {
49+
const now = performance.now() / 1000;
50+
dt = now - t;
51+
52+
T += dt;
53+
54+
let _fps = 1 / dt;
55+
fps = alphaFilter(fps, _fps, 0.05);
56+
}
57+
58+
t = performance.now() / 1000;
59+
60+
if (!text) {
61+
text = document.getElementById("text");
62+
} else {
63+
text.innerHTML =
64+
`fn: ${frameNum}<br>fps: ${fps.toFixed(0)}<br>` +
65+
`dt: ${(dt * 1000).toFixed(0)} ms<br>` +
66+
`T: ${(T).toFixed(0)} s<br>`
67+
}
68+
69+
70+
frameNum++;
71+
72+
requestAnimationFrame(animate);
73+
}
74+
75+
const audioDelay = 1000;
76+
77+
document.addEventListener("DOMContentLoaded", () => {
78+
setTimeout(() => {
79+
const audio = new Audio("sounds/test.mp3");
80+
// audio.loop = true;
81+
audio.play();
82+
audio.onended = () => {
83+
setTimeout(() => {
84+
audio.currentTime = 0;
85+
audio.play();
86+
}, audioDelay);
87+
}
88+
}, audioDelay);
89+
});
90+
91+
requestAnimationFrame(animate);
92+
</script>
93+
</head>
94+
<body>
95+
<div class="wrapper">
96+
<div id="text" class="container" style="background-color: #ff775c;"></div>
97+
</div>
98+
</body>
99+
</html>

html/sounds/test.mp3

82 KB
Binary file not shown.

0 commit comments

Comments
 (0)