提交 2d83330b 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 71ab2bba
...@@ -26,7 +26,7 @@ class Earth(Body): ...@@ -26,7 +26,7 @@ class Earth(Body):
def __init__(self, name="地球", mass=5.97237e24, rotate_angle=23.44, def __init__(self, name="地球", mass=5.97237e24, rotate_angle=23.44,
init_position=[0, 0, 1 * AU], init_position=[0, 0, 1 * AU],
init_velocity=[-29.79, 0, 0], init_velocity=[-29.79, 0, 0],
color=(7, 0, 162), texture="earth1.jpg",text_color=None, color=(7, 0, 162), texture="earth1.jpg", text_color=None,
size_scale=1.0, distance_scale=1.0, size_scale=1.0, distance_scale=1.0,
rotation_speed=15, ignore_mass=False, rotation_speed=15, ignore_mass=False,
trail_color=None, show_name=False, trail_color=None, show_name=False,
......
...@@ -17,13 +17,14 @@ from simulators.ursina.ursina_event import UrsinaEvent ...@@ -17,13 +17,14 @@ from simulators.ursina.ursina_event import UrsinaEvent
FACTOR = 10 FACTOR = 10
# 地球和月球之间的距离常量,距地距离约: 363104 至 405696 km,平均距离 384000 km # 地球和月球之间的距离常量,距地距离约: 363104 至 405696 km,平均距离 384000 km
E_M_DISTANCE = 405696 * FACTOR E_M_DISTANCE = 405696 * FACTOR
earth = Earth("地球", size_scale=FACTOR, init_position=[0, 0, 0]) earth1 = Earth("地球1", size_scale=FACTOR, init_position=[0, 0, 0])
moon = Moon("月球", size_scale=FACTOR, init_position=[E_M_DISTANCE, 0, 0]) moon = Moon("月球", size_scale=FACTOR, init_position=[E_M_DISTANCE, 0, 0])
earth2 = Earth("地球2", texture="earth2.jpg", size_scale=FACTOR)
bodies = [ bodies = [
earth, moon, earth1, moon,
Mercury(name="水星", size_scale=FACTOR), Mercury(name="水星", size_scale=FACTOR),
Venus(name="金星", size_scale=FACTOR), Venus(name="金星", size_scale=FACTOR),
earth2,
Mars(name="火星", size_scale=FACTOR), Mars(name="火星", size_scale=FACTOR),
Jupiter(name="木星", size_scale=FACTOR), Jupiter(name="木星", size_scale=FACTOR),
Saturn(name="土星", size_scale=FACTOR).show_rings(False), Saturn(name="土星", size_scale=FACTOR).show_rings(False),
...@@ -37,20 +38,24 @@ index = 2 ...@@ -37,20 +38,24 @@ index = 2
last_total_hours = 0 last_total_hours = 0
if __name__ == '__main__': if __name__ == '__main__':
last_diameter = earth.diameter * FACTOR / 2 last_diameter = earth1.diameter * FACTOR / 2
plant_positions = [] plant_positions = []
for i, body in enumerate(bodies): for i, body in enumerate(bodies):
body.rotation_speed /= 10 # 星体的旋转速度减小10倍
body.ignore_mass = True body.ignore_mass = True
body.init_velocity = [0, 0, 0] body.init_velocity = [0, 0, 0]
if i >= 2: # 从第三个星球(水星)开始 if i >= 2: # 从第三个星球(水星)开始
plant_positions.append([(body.diameter * FACTOR / 2) + last_diameter, 0, 0]) plant_positions.append([(body.diameter * FACTOR / 2) + last_diameter, 0, 0])
last_diameter += body.diameter * FACTOR last_diameter += body.diameter * FACTOR
# print(body)
def on_ready(): def on_ready():
# 运行前触发 # 运行前触发
# 为了较好的立体效果,可以增加太阳光线,光线直射地球(target=earth) # 为了较好的立体效果,可以增加太阳光线,光线直射地球(target=earth)
create_directional_light(position=(E_M_DISTANCE / 2, 0, -E_M_DISTANCE * 100), light_num=3, target=earth) create_directional_light(position=(E_M_DISTANCE / 2, E_M_DISTANCE * 20, -E_M_DISTANCE * 100),
light_num=3,
target=earth1)
def on_timer_changed(time_data: TimeData): def on_timer_changed(time_data: TimeData):
...@@ -59,6 +64,7 @@ if __name__ == '__main__': ...@@ -59,6 +64,7 @@ if __name__ == '__main__':
if index >= len(bodies): if index >= len(bodies):
return return
total_hours = int(time_data.total_hours) total_hours = int(time_data.total_hours)
# 每间隔3个小时,将行星按顺序进行摆放在地球和月球之间
if total_hours % 3 == 0 and last_total_hours != total_hours: if total_hours % 3 == 0 and last_total_hours != total_hours:
last_total_hours = total_hours last_total_hours = total_hours
bodies[index].init_position = plant_positions[index - 2] bodies[index].init_position = plant_positions[index - 2]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册