提交 3f8f23e1 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 eea47c4a
...@@ -76,10 +76,12 @@ class 星球: ...@@ -76,10 +76,12 @@ class 星球:
# 初始化图形 # 初始化图形
图形, 坐标轴 = plt.subplots() 图形, 坐标轴 = plt.subplots()
星球列表 = [] 星球列表 = []
# 时间步长,单位:s
时间步长 = 0.01
def 场景1(): def 场景1():
global 星球列表 global 星球列表, 时间步长
时间步长 = 0.01
# 创建星球列表 # 创建星球列表
星球列表 = [ 星球列表 = [
星球(质量=1e12, 位置=[0, 0], 速度=[0, 1], 颜色='red', 名称="太阳", 名称偏移=[2, 0]), 星球(质量=1e12, 位置=[0, 0], 速度=[0, 1], 颜色='red', 名称="太阳", 名称偏移=[2, 0]),
...@@ -91,7 +93,8 @@ def 场景1(): ...@@ -91,7 +93,8 @@ def 场景1():
def 场景2(): def 场景2():
global 星球列表 global 星球列表, 时间步长
时间步长 = 0.2
星球列表 = [ 星球列表 = [
星球(质量=1e12, 位置=[10, 0], 速度=[0, 1], 颜色='blue', 名称="蓝星", 名称偏移=[2, 0]), 星球(质量=1e12, 位置=[10, 0], 速度=[0, 1], 颜色='blue', 名称="蓝星", 名称偏移=[2, 0]),
星球(质量=1e12, 位置=[-10, 0], 速度=[0, -1], 颜色='green', 名称="绿星", 名称偏移=[2, 0]) 星球(质量=1e12, 位置=[-10, 0], 速度=[0, -1], 颜色='green', 名称="绿星", 名称偏移=[2, 0])
...@@ -100,8 +103,8 @@ def 场景2(): ...@@ -100,8 +103,8 @@ def 场景2():
坐标轴.set_ylim(-50, 50) 坐标轴.set_ylim(-50, 50)
# 场景1() 场景1()
场景2() # 场景2()
# 调整边距 # 调整边距
plt.subplots_adjust(left=0.05, bottom=0.04, right=0.97, top=0.97, wspace=0.4, hspace=0.4) 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 更新(帧): ...@@ -131,8 +134,8 @@ def 更新(帧):
:param 帧: 当前动画的帧数,无单位 :param 帧: 当前动画的帧数,无单位
""" """
# 时间步长,单位:s global 时间步长
时间步长 = 0.01
for 星球 in 星球列表: for 星球 in 星球列表:
星球.更新(星球列表, 时间步长) 星球.更新(星球列表, 时间步长)
for i, 星球 in enumerate(星球列表): for i, 星球 in enumerate(星球列表):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册