Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -277,58 +277,53 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
277 |
<audio id="bark" src="{bark_sound}"></audio>
|
278 |
<canvas id="fireworks" style="position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:0;"></canvas>
|
279 |
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
const
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
document.
|
301 |
-
avatar.onmouseup =
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
const
|
315 |
-
const
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
}}, i * 20);
|
328 |
-
}}
|
329 |
-
}}
|
330 |
-
setInterval(firework, 1800);
|
331 |
-
</script>
|
332 |
""")
|
333 |
|
334 |
# 绑定交互
|
|
|
277 |
<audio id="bark" src="{bark_sound}"></audio>
|
278 |
<canvas id="fireworks" style="position:fixed;top:0;left:0;width:100vw;height:100vh;pointer-events:none;z-index:0;"></canvas>
|
279 |
|
280 |
+
<script>
|
281 |
+
const tracks = ["{music1}", "{music2}"];
|
282 |
+
const audio = document.getElementById("bg-music");
|
283 |
+
let current = 0;
|
284 |
+
audio.addEventListener("ended", () => {
|
285 |
+
current = (current + 1) % tracks.length;
|
286 |
+
audio.src = tracks[current];
|
287 |
+
audio.play();
|
288 |
+
});
|
289 |
+
|
290 |
+
const avatar = document.getElementById("sophia-avatar");
|
291 |
+
avatar.onmousedown = function(e) {
|
292 |
+
const shiftX = e.clientX - avatar.getBoundingClientRect().left;
|
293 |
+
const shiftY = e.clientY - avatar.getBoundingClientRect().top;
|
294 |
+
function moveAt(e) {
|
295 |
+
avatar.style.left = e.pageX - shiftX + 'px';
|
296 |
+
avatar.style.top = e.pageY - shiftY + 'px';
|
297 |
+
}
|
298 |
+
document.addEventListener('mousemove', moveAt);
|
299 |
+
avatar.onmouseup = function() {
|
300 |
+
document.removeEventListener('mousemove', moveAt);
|
301 |
+
avatar.onmouseup = null;
|
302 |
+
};
|
303 |
+
};
|
304 |
+
avatar.ondragstart = () => false;
|
305 |
+
avatar.addEventListener("click", () => {
|
306 |
+
document.getElementById("bark").play();
|
307 |
+
});
|
308 |
+
|
309 |
+
const canvas = document.getElementById("fireworks");
|
310 |
+
const ctx = canvas.getContext("2d");
|
311 |
+
canvas.width = window.innerWidth;
|
312 |
+
canvas.height = window.innerHeight;
|
313 |
+
function firework() {
|
314 |
+
const x = Math.random() * canvas.width;
|
315 |
+
const y = Math.random() * canvas.height;
|
316 |
+
for (let i = 0; i < 30; i++) {
|
317 |
+
setTimeout(() => {
|
318 |
+
ctx.beginPath();
|
319 |
+
ctx.arc(x, y, Math.random() * 3 + 2, 0, Math.PI * 2);
|
320 |
+
ctx.fillStyle = `hsl(${Math.random() * 360}, 100%, 60%)`;
|
321 |
+
ctx.fill();
|
322 |
+
}, i * 20);
|
323 |
+
}
|
324 |
+
}
|
325 |
+
setInterval(firework, 1800);
|
326 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
327 |
""")
|
328 |
|
329 |
# 绑定交互
|