Lightning strike simulation
Version 1.0.0 (1.61 KB) by
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()
Cite As
Mohamed Kbaier (2024). Lightning strike simulation (https://www.mathworks.com/matlabcentral/fileexchange/166086-lightning-strike-simulation), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |