Update app.py
Browse files
app.py
CHANGED
|
@@ -1,112 +1,100 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
st.title("
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# JavaScript code for the brain-shaped animation with SVG text
|
| 8 |
js_code = """
|
| 9 |
-
<
|
| 10 |
-
|
| 11 |
<script>
|
| 12 |
-
const
|
| 13 |
-
const
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
let t = 0;
|
| 16 |
-
|
| 17 |
function mag(x, y) {
|
| 18 |
return Math.sqrt(x * x + y * y);
|
| 19 |
}
|
| 20 |
-
|
| 21 |
-
function
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
-
|
| 39 |
-
function
|
| 40 |
-
// Clear
|
| 41 |
-
|
| 42 |
-
|
| 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 |
-
|
| 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
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
}
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
</script>
|
| 88 |
"""
|
| 89 |
-
|
| 90 |
-
#
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
""", unsafe_allow_html=True)
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
-
|
|
|
|
| 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()
|