Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.animation as animation
|
5 |
+
|
6 |
+
# Set up page configuration
|
7 |
+
st.set_page_config(page_title="Hithesh Rai - Interactive Physics Model", page_icon="🔬")
|
8 |
+
|
9 |
+
# Header
|
10 |
+
st.title("Interactive Bohr Model of the Atom")
|
11 |
+
st.subheader("Visualize electrons orbiting around a nucleus")
|
12 |
+
|
13 |
+
# About Section
|
14 |
+
st.write("""
|
15 |
+
Explore a simple interactive model of an atom based on the Bohr model, where electrons orbit a nucleus in defined circular paths. Use the controls to set the number of electrons and watch them orbit in real time!
|
16 |
+
""")
|
17 |
+
|
18 |
+
# Input for number of electrons
|
19 |
+
num_electrons = st.slider("Select the number of electrons", 1, 5, 3)
|
20 |
+
|
21 |
+
# Create figure and axis
|
22 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
23 |
+
ax.set_xlim(-10, 10)
|
24 |
+
ax.set_ylim(-10, 10)
|
25 |
+
ax.set_aspect('equal')
|
26 |
+
ax.axis('off')
|
27 |
+
|
28 |
+
# Set up nucleus
|
29 |
+
nucleus, = ax.plot(0, 0, 'o', color='orange', markersize=10, label="Nucleus")
|
30 |
+
|
31 |
+
# Colors for electron orbits
|
32 |
+
orbit_colors = ['blue', 'green', 'red', 'purple', 'cyan']
|
33 |
+
|
34 |
+
# Set up electron orbits based on selected number
|
35 |
+
electrons = []
|
36 |
+
orbits = []
|
37 |
+
for i in range(num_electrons):
|
38 |
+
radius = 2 + 2 * i
|
39 |
+
theta = np.linspace(0, 2 * np.pi, 100)
|
40 |
+
x = radius * np.cos(theta)
|
41 |
+
y = radius * np.sin(theta)
|
42 |
+
orbit, = ax.plot(x, y, linestyle="--", color=orbit_colors[i % len(orbit_colors)], alpha=0.5)
|
43 |
+
electron, = ax.plot([], [], 'o', color=orbit_colors[i % len(orbit_colors)], markersize=6)
|
44 |
+
electrons.append(electron)
|
45 |
+
orbits.append(orbit)
|
46 |
+
|
47 |
+
# Animation update function
|
48 |
+
def update(frame):
|
49 |
+
for i, electron in enumerate(electrons):
|
50 |
+
radius = 2 + 2 * i
|
51 |
+
x = radius * np.cos(frame * 0.1 + i * np.pi / num_electrons)
|
52 |
+
y = radius * np.sin(frame * 0.1 + i * np.pi / num_electrons)
|
53 |
+
electron.set_data(x, y)
|
54 |
+
return electrons
|
55 |
+
|
56 |
+
# Animation
|
57 |
+
ani = animation.FuncAnimation(fig, update, frames=range(200), interval=50, blit=True)
|
58 |
+
|
59 |
+
# Display animation in Streamlit
|
60 |
+
st.pyplot(fig)
|
61 |
+
|
62 |
+
# Footer
|
63 |
+
st.write("Explore the Bohr Model! Adjust the number of electrons and watch them orbit around the nucleus.")
|