awacke1 commited on
Commit
d19c729
·
verified ·
1 Parent(s): 4084515

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -89
app.py CHANGED
@@ -1,112 +1,100 @@
1
  import streamlit as st
2
 
3
- def create_brain_animation_app():
4
- st.title("AI Memory & Brain Visualization")
5
- st.write("This visualization represents AI learning and memory enhancement, shaped like a brain's neocortex.")
6
-
7
- # JavaScript code for the brain-shaped animation with SVG text
8
  js_code = """
9
- <svg id="brainCanvas" width="100%" height="100%" style="position:fixed; top:0; left:0;"></svg>
10
-
11
  <script>
12
- const svg = document.getElementById('brainCanvas');
13
- const ns = 'http://www.w3.org/2000/svg';
14
-
 
 
 
 
15
  let t = 0;
16
-
17
  function mag(x, y) {
18
  return Math.sqrt(x * x + y * y);
19
  }
20
-
21
- function brainShape(x, y) {
22
- let k = x/8 - 25, e = y/8 - 25;
23
- let d = mag(k, e)**2 / 99;
 
24
 
25
- let q = x/3 + k * 0.5 / Math.cos(y*5) * Math.sin(d*d - t);
26
- let c = d/2 - t/8;
27
 
28
- let xPos = q * Math.sin(c) + e * Math.sin(d + k - t) + svg.clientWidth / 2;
29
- let yPos = (q + y/8 + d*9) * Math.cos(c) + svg.clientHeight / 2;
30
 
31
- return[xPos, yPos];
32
  }
33
-
34
  function getColor(x, y, t) {
 
35
  const hue = (Math.sin(t/2) * 360 + x/3 + y/3) % 360;
36
- return `hsl(${hue}, 70%, 50%)`;
 
 
37
  }
38
-
39
- function drawBrain() {
40
- // Clear previous circles
41
- while (svg.firstChild) {
42
- svg.removeChild(svg.firstChild);
43
- }
44
-
45
- const circleRadius = 1;
46
- for (let y = 99; y < svg.clientHeight - 99; y += 4) {
47
- for (let x = 99; x < svg.clientWidth - 99; x += 2) {
48
- const[px, py] = brainShape(x, y);
49
- if (Math.sqrt(px*px + py*py) > svg.clientWidth * 0.3 && Math.sqrt(px*px + py*py) < svg.clientWidth * 0.6) {
50
- const circle = document.createElementNS(ns, 'circle');
51
- circle.setAttribute('cx', px);
52
- circle.setAttribute('cy', py);
53
- circle.setAttribute('r', circleRadius);
54
- circle.setAttribute('fill', getColor(x, y, t));
55
- svg.appendChild(circle);
56
- }
57
- }
58
- }
59
 
60
- t += Math.PI / 180;
61
- requestAnimationFrame(drawBrain);
62
- }
63
-
64
- function addScrollingText(text) {
65
- const textElement = document.createElementNS(ns, 'text');
66
- textElement.setAttribute('x', '50%');
67
- textElement.setAttribute('y', '10%');
68
- textElement.setAttribute('dy', '0.3em');
69
- textElement.setAttribute('text-anchor', 'middle');
70
- textElement.setAttribute('fill', 'white');
71
- textElement.setAttribute('font-size', '20px');
72
- textElement.textContent = text;
73
-
74
- svg.appendChild(textElement);
75
 
76
- let startX = 0;
77
- function animateText() {
78
- startX = (startX - 1) % (svg.clientWidth + 200);
79
- textElement.setAttribute('transform', `translate(${startX}, 0)`);
80
- requestAnimationFrame(animateText);
 
 
 
 
 
 
81
  }
82
- animateText();
 
 
83
  }
84
-
85
- drawBrain();
86
- addScrollingText("AI Memory & Brain Visualization");
 
 
 
 
87
  </script>
88
  """
89
-
90
- # Using a different approach for fullscreen element
91
- st.markdown(
92
- f"""
93
- <style>
94
- .full-screen-container {{
95
- position: fixed;
96
- top: 0;
97
- left: 0;
98
- width: 100vw;
99
- height: 100vh;
100
- margin: 0;
101
- padding: 0;
102
- overflow: hidden;
103
- z-index: -1;
104
- }}
105
- </style>
106
- <div class="full-screen-container">
107
- {js_code}
108
- </div>
109
- """, unsafe_allow_html=True)
110
 
111
  if __name__ == "__main__":
112
- create_brain_animation_app()
 
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 = """
8
+ <canvas id="animationCanvas"></canvas>
9
+
10
  <script>
11
+ const canvas = document.getElementById('animationCanvas');
12
+ const ctx = canvas.getContext('2d');
13
+
14
+ // Set canvas size
15
+ canvas.width = 400;
16
+ canvas.height = 400;
17
+
18
  let t = 0;
19
+
20
  function mag(x, y) {
21
  return Math.sqrt(x * x + y * y);
22
  }
23
+
24
+ function a(x, y) {
25
+ const k = x/8 - 25;
26
+ const e = y/8 - 25;
27
+ const d = mag(k, e)**2 / 99;
28
 
29
+ const q = x/3 + k * 0.5 / Math.cos(y*5) * Math.sin(d*d - t);
30
+ const c = d/2 - t/8;
31
 
32
+ const xPos = q * Math.sin(c) + e * Math.sin(d + k - t) + 200;
33
+ const yPos = (q + y/8 + d*9) * Math.cos(c) + 200;
34
 
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
+ """
92
+
93
+ # Combine CSS and JavaScript
94
+ html_content = css + js_code
95
+
96
+ # Display using st.components.v1.html
97
+ st.components.v1.html(html_content, height=450)
 
98
 
99
  if __name__ == "__main__":
100
+ create_animation_app()