File size: 2,721 Bytes
57b3cfe
 
d19c729
 
 
 
57b3cfe
d19c729
 
57b3cfe
d19c729
 
 
 
d92e279
 
d19c729
57b3cfe
d19c729
57b3cfe
 
 
d19c729
 
 
 
 
57b3cfe
d19c729
 
57b3cfe
d19c729
 
57b3cfe
d19c729
57b3cfe
d19c729
57b3cfe
d19c729
57b3cfe
d19c729
 
 
57b3cfe
d19c729
 
 
 
 
57b3cfe
d19c729
a7d2ddc
d19c729
 
 
 
 
 
 
 
 
 
 
57b3cfe
d19c729
 
 
a7d2ddc
d19c729
 
 
 
 
 
 
a7d2ddc
 
d19c729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d92e279
57b3cfe
 
d19c729
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import streamlit as st

def create_animation_app():
    st.title("Animated Spiral Creature")
    
    # JavaScript code for the animation
    js_code = """
    <canvas id="animationCanvas"></canvas>
    
    <script>
    const canvas = document.getElementById('animationCanvas');
    const ctx = canvas.getContext('2d');
    
    // Set canvas size
    canvas.width = 3840;
    canvas.height = 2160;
    
    let t = 0;
    
    function mag(x, y) {
        return Math.sqrt(x * x + y * y);
    }
    
    function a(x, y) {
        const k = x/8 - 25;
        const e = y/8 - 25;
        const d = mag(k, e)**2 / 99;
        
        const q = x/3 + k * 0.5 / Math.cos(y*5) * Math.sin(d*d - t);
        const c = d/2 - t/8;
        
        const xPos = q * Math.sin(c) + e * Math.sin(d + k - t) + 200;
        const yPos = (q + y/8 + d*9) * Math.cos(c) + 200;
        
        return [xPos, yPos];
    }
    
    function getColor(x, y, t) {
        // Create shifting colors based on position and time
        const hue = (Math.sin(t/2) * 360 + x/3 + y/3) % 360;
        const saturation = 70 + Math.sin(t) * 30;
        const lightness = 50 + Math.cos(t/2) * 20;
        return `hsla(${hue}, ${saturation}%, ${lightness}%, 0.5)`;
    }
    
    function draw() {
        // Clear canvas with a fade effect
        ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        
        ctx.lineWidth = 1.5;
        
        for(let y = 99; y < 300; y += 4) {
            for(let x = 99; x < 300; x += 2) {
                const [px, py] = a(x, y);
                const color = getColor(x, y, t);
                
                ctx.strokeStyle = color;
                ctx.beginPath();
                ctx.moveTo(px, py);
                ctx.lineTo(px + 1, py + 1);  // Make points slightly larger
                ctx.stroke();
            }
        }
        
        t += Math.PI / 120;  // Slowed down the animation slightly
        requestAnimationFrame(draw);
    }
    
    // Ensure canvas is cleared on start
    ctx.fillStyle = 'black';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    
    // Start the animation
    draw();
    </script>
    """
    
    # CSS to center the canvas and ensure proper display
    css = """
    <style>
        canvas {
            display: block;
            margin: auto;
            background: black;
        }
        .stApp {
            background-color: black;
        }
    </style>
    """
    
    # Combine CSS and JavaScript
    html_content = css + js_code
    
    # Display using st.components.v1.html
    st.components.v1.html(html_content, height=2160)

if __name__ == "__main__":
    create_animation_app()