| import streamlit as st |
| import numpy as np |
| import matplotlib.pyplot as plt |
| from matplotlib.animation import FuncAnimation |
|
|
| |
| fig, ax = plt.subplots(figsize=(10, 6)) |
| ax.set_xlim(0, 4*np.pi) |
| ax.set_ylim(-2, 2) |
| ax.set_xlabel("Position (m)") |
| ax.set_ylabel("Field Strength") |
| ax.grid(True) |
|
|
| |
| e_line, = ax.plot([], [], lw=2, label='Electric Field (E)') |
| b_line, = ax.plot([], [], lw=2, label='Magnetic Field (B)') |
| ax.legend() |
|
|
| |
| st.sidebar.header("Wave Parameters") |
| frequency = st.sidebar.slider("Frequency (Hz)", 1, 20, 5) |
| wavelength = st.sidebar.slider("Wavelength (m)", 1, 10, 5) |
| amplitude = st.sidebar.slider("Amplitude (V/m)", 0.1, 2.0, 1.0) |
|
|
| |
| def animate(i): |
| x = np.linspace(0, 4*np.pi, 1000) |
| phase = 2 * np.pi * frequency * (i/30) |
| |
| |
| e = amplitude * np.sin((2*np.pi*x)/wavelength - phase) |
| |
| |
| b = (amplitude/3e8) * np.sin((2*np.pi*x)/wavelength - phase) |
| |
| e_line.set_data(x, e) |
| b_line.set_data(x, b) |
| return e_line, b_line |
|
|
| |
| ani = FuncAnimation(fig, animate, frames=100, interval=50, blit=True) |
| st.pyplot(fig) |
|
|