Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = """
|
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 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 |
+
"""
|
73 |
+
|
74 |
+
# Combine CSS and JavaScript
|
75 |
+
html_content = css + js_code
|
76 |
+
|
77 |
+
# Display using st.components.v1.html
|
78 |
+
st.components.v1.html(html_content, height=450)
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
create_animation_app()
|