Lightning strike simulation

版本 1.0.0 (1.6 KB) 作者: Mohamed Kbaier
Lightning strike simulation, wave coded in Python and it's possible to call it in Matlab Simulink
12.0 次下载
更新时间 2024/5/18

查看许可证

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()

引用格式

Mohamed Kbaier (2024). Lightning strike simulation (https://www.mathworks.com/matlabcentral/fileexchange/166086-lightning-strike-simulation), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2024a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0