Lightning strike simulation
Version 1.0.0 (1,61 ko) par
Mohamed Kbaier
Lightning strike simulation, wave coded in Python and it's possible to call it in Matlab Simulink
Lightning strike simulation, wave coded in Python and it's possible to call it in Matlab Simulink:
Code:
import numpy as np
import matplotlib.pyplot as plt
from tkinter import Tk, Button, Label, Frame
import matplotlib.animation as animation
def simulate_lightning_strike():
# Simulating lightning strike coordinates
x = np.random.uniform(-10, 10)
y = np.random.uniform(-10, 10)
return x, y
def plot_strike(x, y):
# Plotting lightning strike
plt.scatter(x, y, color='red', marker='x')
plt.xlim(-20, 20)
plt.ylim(-20, 20)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Lightning Strike')
plt.grid(True)
def generate_strike():
x, y = simulate_lightning_strike()
plot_strike(x, y)
# GUI setup
root = Tk()
root.title("Lightning Strike Simulation")
root.geometry("200x100")
frame = Frame(root)
frame.pack()
btn_generate = Button(frame, text="Generate Strike", command=generate_strike)
btn_generate.pack(side="left")
btn_exit = Button(frame, text="Exit", command=root.destroy)
btn_exit.pack(side="left")
# Animation setup
fig, ax = plt.subplots()
ax.set_xlim(-20, 20)
ax.set_ylim(-20, 20)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_title('Lightning Strike Animation')
ax.grid(True)
line, = ax.plot([], [], 'ro-', animated=True)
def animate(i):
x, y = simulate_lightning_strike()
line.set_data(x, y)
return line,
ani = animation.FuncAnimation(fig, animate, frames=100, interval=100, blit=True)
plt.show()
root.mainloop()
Citation pour cette source
Mohamed Kbaier (2026). Lightning strike simulation (https://fr.mathworks.com/matlabcentral/fileexchange/166086-lightning-strike-simulation), MATLAB Central File Exchange. Extrait(e) le .
Compatibilité avec les versions de MATLAB
Créé avec
R2024a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS LinuxTags
Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
| Version | Publié le | Notes de version | |
|---|---|---|---|
| 1.0.0 |
