File size: 1,951 Bytes
ebcea2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

def create_animation_app():
    st.title("Animated Pattern")
    
    # 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 = 400;
    canvas.height = 400;
    
    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 draw() {
        ctx.fillStyle = 'rgba(6, 6, 6, 0.3)';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        
        ctx.strokeStyle = 'rgba(255, 255, 255, 0.376)';
        
        for(let y = 99; y < 300; y += 5) {
            for(let x = 99; x < 300; x++) {
                const [px, py] = a(x, y);
                ctx.beginPath();
                ctx.moveTo(px, py);
                ctx.lineTo(px, py);
                ctx.stroke();
            }
        }
        
        t += Math.PI / 60;
        requestAnimationFrame(draw);
    }
    
    // Start the animation
    draw();
    </script>
    """
    
    # CSS to center the canvas
    css = """
    <style>
        canvas {
            display: block;
            margin: auto;
            background: #000;
        }
    </style>
    """
    
    # Combine CSS and JavaScript
    html_content = css + js_code
    
    # Display using st.components.v1.html
    st.components.v1.html(html_content, height=450)

if __name__ == "__main__":
    create_animation_app()