awacke1 commited on
Commit
101dcb0
·
verified ·
1 Parent(s): ebcea2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
 
3
  def create_animation_app():
4
- st.title("Animated Pattern")
5
 
6
  # JavaScript code for the animation
7
  js_code = """
@@ -35,38 +35,57 @@ def create_animation_app():
35
  return [xPos, yPos];
36
  }
37
 
 
 
 
 
 
 
 
 
38
  function draw() {
39
- ctx.fillStyle = 'rgba(6, 6, 6, 0.3)';
 
40
  ctx.fillRect(0, 0, canvas.width, canvas.height);
41
 
42
- ctx.strokeStyle = 'rgba(255, 255, 255, 0.376)';
43
 
44
- for(let y = 99; y < 300; y += 5) {
45
- for(let x = 99; x < 300; x++) {
46
  const [px, py] = a(x, y);
 
 
 
47
  ctx.beginPath();
48
  ctx.moveTo(px, py);
49
- ctx.lineTo(px, py);
50
  ctx.stroke();
51
  }
52
  }
53
 
54
- t += Math.PI / 60;
55
  requestAnimationFrame(draw);
56
  }
57
 
 
 
 
 
58
  // Start the animation
59
  draw();
60
  </script>
61
  """
62
 
63
- # CSS to center the canvas
64
  css = """
65
  <style>
66
  canvas {
67
  display: block;
68
  margin: auto;
69
- background: #000;
 
 
 
70
  }
71
  </style>
72
  """
 
1
  import streamlit as st
2
 
3
  def create_animation_app():
4
+ st.title("Animated Spiral Creature")
5
 
6
  # JavaScript code for the animation
7
  js_code = """
 
35
  return [xPos, yPos];
36
  }
37
 
38
+ function getColor(x, y, t) {
39
+ // Create shifting colors based on position and time
40
+ const hue = (Math.sin(t/2) * 360 + x/3 + y/3) % 360;
41
+ const saturation = 70 + Math.sin(t) * 30;
42
+ const lightness = 50 + Math.cos(t/2) * 20;
43
+ return `hsla(${hue}, ${saturation}%, ${lightness}%, 0.5)`;
44
+ }
45
+
46
  function draw() {
47
+ // Clear canvas with a fade effect
48
+ ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
49
  ctx.fillRect(0, 0, canvas.width, canvas.height);
50
 
51
+ ctx.lineWidth = 1.5;
52
 
53
+ for(let y = 99; y < 300; y += 4) {
54
+ for(let x = 99; x < 300; x += 2) {
55
  const [px, py] = a(x, y);
56
+ const color = getColor(x, y, t);
57
+
58
+ ctx.strokeStyle = color;
59
  ctx.beginPath();
60
  ctx.moveTo(px, py);
61
+ ctx.lineTo(px + 1, py + 1); // Make points slightly larger
62
  ctx.stroke();
63
  }
64
  }
65
 
66
+ t += Math.PI / 120; // Slowed down the animation slightly
67
  requestAnimationFrame(draw);
68
  }
69
 
70
+ // Ensure canvas is cleared on start
71
+ ctx.fillStyle = 'black';
72
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
73
+
74
  // Start the animation
75
  draw();
76
  </script>
77
  """
78
 
79
+ # CSS to center the canvas and ensure proper display
80
  css = """
81
  <style>
82
  canvas {
83
  display: block;
84
  margin: auto;
85
+ background: black;
86
+ }
87
+ .stApp {
88
+ background-color: black;
89
  }
90
  </style>
91
  """