diff --git a/simulators/mpl_2d_simulator.py b/simulators/mpl_2d_simulator.py index f5b2958f84324fe03c056290b6f638952c26ea20..d0899e668297bbf7798a56ecbf0423abc977920a 100644 --- a/simulators/mpl_2d_simulator.py +++ b/simulators/mpl_2d_simulator.py @@ -76,10 +76,12 @@ class 星球: # 初始化图形 图形, 坐标轴 = plt.subplots() 星球列表 = [] - +# 时间步长,单位:s +时间步长 = 0.01 def 场景1(): - global 星球列表 + global 星球列表, 时间步长 + 时间步长 = 0.01 # 创建星球列表 星球列表 = [ 星球(质量=1e12, 位置=[0, 0], 速度=[0, 1], 颜色='red', 名称="太阳", 名称偏移=[2, 0]), @@ -91,7 +93,8 @@ def 场景1(): def 场景2(): - global 星球列表 + global 星球列表, 时间步长 + 时间步长 = 0.2 星球列表 = [ 星球(质量=1e12, 位置=[10, 0], 速度=[0, 1], 颜色='blue', 名称="蓝星", 名称偏移=[2, 0]), 星球(质量=1e12, 位置=[-10, 0], 速度=[0, -1], 颜色='green', 名称="绿星", 名称偏移=[2, 0]) @@ -100,8 +103,8 @@ def 场景2(): 坐标轴.set_ylim(-50, 50) -# 场景1() -场景2() +场景1() +# 场景2() # 调整边距 plt.subplots_adjust(left=0.05, bottom=0.04, right=0.97, top=0.97, wspace=0.4, hspace=0.4) @@ -131,8 +134,8 @@ def 更新(帧): :param 帧: 当前动画的帧数,无单位 """ - # 时间步长,单位:s - 时间步长 = 0.01 + global 时间步长 + for 星球 in 星球列表: 星球.更新(星球列表, 时间步长) for i, 星球 in enumerate(星球列表):