Ronaldo1111 commited on
Commit
368bc02
·
verified ·
1 Parent(s): 701ecdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -52
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
- <script>
281
- // 播放背景音乐轮播
282
- const tracks = ["{music1}", "{music2}"];
283
- const audio = document.getElementById("bg-music");
284
- let current = 0;
285
- audio.addEventListener("ended", () => {{
286
- current = (current + 1) % tracks.length;
287
- audio.src = tracks[current];
288
- audio.play();
289
- }});
290
-
291
- // 拖动头像
292
- const avatar = document.getElementById("sophia-avatar");
293
- avatar.onmousedown = function(e) {{
294
- const shiftX = e.clientX - avatar.getBoundingClientRect().left;
295
- const shiftY = e.clientY - avatar.getBoundingClientRect().top;
296
- function moveAt(e) {{
297
- avatar.style.left = e.pageX - shiftX + 'px';
298
- avatar.style.top = e.pageY - shiftY + 'px';
299
- }}
300
- document.addEventListener('mousemove', moveAt);
301
- avatar.onmouseup = function() {{
302
- document.removeEventListener('mousemove', moveAt);
303
- avatar.onmouseup = null;
304
- }};
305
- }};
306
- avatar.ondragstart = () => false;
307
-
308
- // 点击头像播放汪汪叫
309
- avatar.addEventListener("click", () => {{
310
- document.getElementById("bark").play();
311
- }});
312
-
313
- // 烟花特效
314
- const canvas = document.getElementById("fireworks");
315
- const ctx = canvas.getContext("2d");
316
- canvas.width = window.innerWidth;
317
- canvas.height = window.innerHeight;
318
- function firework() {{
319
- const x = Math.random() * canvas.width;
320
- const y = Math.random() * canvas.height;
321
- for (let i = 0; i < 30; i++) {{
322
- setTimeout(() => {{
323
- ctx.beginPath();
324
- ctx.arc(x, y, Math.random() * 3 + 2, 0, Math.PI * 2);
325
- ctx.fillStyle = `hsl(${Math.random() * 360}, 100%, 60%)`;
326
- ctx.fill();
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
  # 绑定交互