File size: 3,861 Bytes
f4108d0
 
 
 
 
 
 
 
 
 
 
 
61a6d43
f4108d0
 
 
 
61a6d43
 
f4108d0
 
 
 
 
61a6d43
 
 
 
f4108d0
8b542bc
f4108d0
 
 
 
8b542bc
 
 
f4108d0
 
 
 
 
 
61a6d43
 
 
 
f4108d0
8b542bc
f4108d0
 
 
 
 
 
 
 
 
8b542bc
f4108d0
 
 
8b542bc
 
f4108d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b542bc
f4108d0
 
 
0b9d5e3
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
101
102
103
104
105
import gradio as gr

# HTML and CSS for the solar system visualization
html_code = """
<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: #000;
            font-family: Arial, sans-serif;
        }
        .solar-system {
            position: relative;
            width: 100vw;
            height: 50vh; /* Adjusted height for scrolling */
            overflow: hidden;
        }
        .planet {
            position: absolute;
            border-radius: 50%;
            cursor: pointer;
            transition: transform 0.3s;
        }
        .planet:hover {
            transform: scale(1.2); /* Scale up the planet on hover */
        }
        .info-box {
            background: rgba(0, 0, 0, 0.7);
            color: #fff;
            padding: 10px;
            border-radius: 5px;
            margin-top: 20px;
            width: 100%;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="solar-system" id="solar-system">
        <div class="planet" id="sun" style="width: 100px; height: 100px; background: yellow; top: 50%; left: 50%; transform: translate(-50%, -50%);"></div>
        <div class="planet" id="mercury" style="width: 20px; height: 20px; background: gray;"></div>
        <div class="planet" id="venus" style="width: 30px; height: 30px; background: orange;"></div>
        <div class="planet" id="earth" style="width: 40px; height: 40px; background: blue;"></div>
        <div class="planet" id="mars" style="width: 30px; height: 30px; background: red;"></div>
    </div>
    <div class="info-box" id="info-box">Click on a planet to see information</div>
    <script>
        const planets = [
            { id: 'sun', name: 'Sun', facts: 'The Sun is the star at the center of the Solar System.' },
            { id: 'mercury', name: 'Mercury', facts: 'Mercury is the smallest planet in the Solar System.' },
            { id: 'venus', name: 'Venus', facts: 'Venus has a thick, toxic atmosphere filled with carbon dioxide.' },
            { id: 'earth', name: 'Earth', facts: 'Earth is the only planet known to support life.' },
            { id: 'mars', name: 'Mars', facts: 'Mars is known as the Red Planet due to its reddish appearance.' },
        ];

        const infoBox = document.getElementById('info-box');

        planets.forEach(planet => {
            const element = document.getElementById(planet.id);
            element.addEventListener('click', () => {
                infoBox.innerHTML = `<strong>${planet.name}</strong><br>${planet.facts}`;
            });
        });

        function animate() {
            const solarSystem = document.getElementById('solar-system');
            const time = new Date().getTime() * 0.0005;
            const radius = Math.min(solarSystem.clientWidth, solarSystem.clientHeight) / 2.5;

            planets.forEach((planet, index) => {
                if (planet.id !== 'sun') {
                    const element = document.getElementById(planet.id);
                    const angle = time + index * 0.5;
                    const x = Math.cos(angle) * radius + solarSystem.clientWidth / 2;
                    const y = Math.sin(angle) * radius + solarSystem.clientHeight / 2;
                    element.style.left = `${x}px`;
                    element.style.top = `${y}px`;
                }
            });

            requestAnimationFrame(animate);
        }

        animate();
    </script>
</body>
</html>
"""

def solar_system_simulator():
    return gr.HTML(html_code)

demo = gr.Interface(
    fn=solar_system_simulator,
    inputs=[],
    outputs="html",
    title="Solar System Simulator",
    description="A colorful and animated solar system simulator. Click on the planets to see key facts."
)

if __name__ == "__main__":
    demo.launch()