提交 143fac2c 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 1ab087ee
...@@ -327,6 +327,9 @@ class Body(metaclass=ABCMeta): ...@@ -327,6 +327,9 @@ class Body(metaclass=ABCMeta):
self.__append_history(self.__his_acc, self.acceleration) self.__append_history(self.__his_acc, self.acceleration)
# print(self.name, "his pos->", self.__his_pos) # print(self.name, "his pos->", self.__his_pos)
def clear_his_position(self):
self.__his_pos.clear()
def his_position(self): def his_position(self):
""" """
历史位置 历史位置
......
...@@ -220,7 +220,11 @@ class System(object): ...@@ -220,7 +220,11 @@ class System(object):
positions = [] positions = []
for body in valid_bodies: for body in valid_bodies:
masses.append(body.mass) masses.append(body.mass)
positions.append(body.position * 1000) position = body.position
if not isinstance(position, np.ndarray):
position = np.array(position)
position = position * 1000
positions.append(position)
accelerations = self.calculate_gravitational_accelerations(masses, positions) accelerations = self.calculate_gravitational_accelerations(masses, positions)
......
...@@ -316,6 +316,9 @@ class Obj(metaclass=ABCMeta): ...@@ -316,6 +316,9 @@ class Obj(metaclass=ABCMeta):
self.__append_history(self.__his_acc, self.acceleration) self.__append_history(self.__his_acc, self.acceleration)
# print(self.name, "his pos->", self.__his_pos) # print(self.name, "his pos->", self.__his_pos)
def clear_his_position(self):
self.__his_pos.clear()
def his_position(self): def his_position(self):
""" """
历史位置 历史位置
......
...@@ -36,8 +36,8 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes): ...@@ -36,8 +36,8 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes):
# 分别保存太阳碰撞次数、木星碰撞次数、地球碰撞次数、月球碰撞次数、木星保护次数、月球保护次数 # 分别保存太阳碰撞次数、木星碰撞次数、地球碰撞次数、月球碰撞次数、木星保护次数、月球保护次数
self.colliding_count = [0, 0, 0, 0, 0, 0] self.colliding_count = [0, 0, 0, 0, 0, 0]
self.sun = Sun(name="太阳", size_scale=0.85e2, show_trail=False) # 太阳放大 80 倍,距离保持不变 self.sun = Sun(name="太阳", size_scale=0.85e2, show_trail=False) # 太阳放大 80 倍,距离保持不变
self.jupiter = Jupiter(name="木星", size_scale=0.45e3, ignore_mass=True, show_trail=False) # 木星放大 600 倍,距离保持不变 self.jupiter = Jupiter(name="木星", size_scale=0.45e3, ignore_mass=False, show_trail=False) # 木星放大 600 倍,距离保持不变
self.earth = Earth(name="地球", size_scale=2.5e3, ignore_mass=True, show_trail=False ) # 地球放大 2000 倍,距离保持不变 self.earth = Earth(name="地球", size_scale=2.5e3, ignore_mass=False, show_trail=False ) # 地球放大 2000 倍,距离保持不变
self.moon = Moon(name="月球", size_scale=3.5e3, # 月球球放大 3000 倍,为了较好的效果,地月距离要比实际大 self.moon = Moon(name="月球", size_scale=3.5e3, # 月球球放大 3000 倍,为了较好的效果,地月距离要比实际大
init_position=[self.earth_moon_d, 0, AU], init_position=[self.earth_moon_d, 0, AU],
init_velocity=[0, 0, 0], init_velocity=[0, 0, 0],
...@@ -58,7 +58,7 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes): ...@@ -58,7 +58,7 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes):
for i in range(comet_num): for i in range(comet_num):
# 随机生成 comet_num 个石头 # 随机生成 comet_num 个石头
comet = self.create_comet(i, gravity_only_for=[self.sun]) comet = self.create_comet(i, gravity_only_for=[self.sun, self.earth, self.jupiter])
# comet = self.create_comet(i, gravity_only_for=[self.sun, self.jupiter, self.earth]) # comet = self.create_comet(i, gravity_only_for=[self.sun, self.jupiter, self.earth])
self.bodies.append(comet) self.bodies.append(comet)
self.comets.append(comet) self.comets.append(comet)
...@@ -248,8 +248,8 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes): ...@@ -248,8 +248,8 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes):
def camera_move(self, time_data): def camera_move(self, time_data):
from ursina import camera from ursina import camera
camera.position += camera.left * 0.01 camera.position += camera.left * 1
camera_look_at(self.sun) camera_look_at(self.sun, rotation_z=0)
def on_ready(self): def on_ready(self):
from ursina import application, window from ursina import application, window
...@@ -264,7 +264,7 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes): ...@@ -264,7 +264,7 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes):
0, "0.0%", 0, "0.0%",
0, 0) 0, 0)
camera_look_at(self.sun) camera_look_at(self.sun)
self.sky = create_sphere_sky(scale=8000) self.sky = create_sphere_sky(scale=8000, texture="bg_pan2.jpg")
self.sky.rotation_y = -180 self.sky.rotation_y = -180
self.sky.rotation_x = -20 self.sky.rotation_x = -20
# self.sky.rotation_z = -65 # self.sky.rotation_z = -65
...@@ -278,9 +278,9 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes): ...@@ -278,9 +278,9 @@ class JupiterMoonProtectsEarthSim(UniverseSimScenes):
# UrsinaConfig.trail_length = 1000 # UrsinaConfig.trail_length = 1000
UrsinaConfig.trail_thickness_factor = 2 UrsinaConfig.trail_thickness_factor = 2
for b in self.bodies: # for b in self.bodies:
if isinstance(b, Rock): # if isinstance(b, Rock):
print("岩石大小", b.name, b.planet.scale_x) # print("岩石大小", b.name, b.planet.scale_x)
if __name__ == '__main__': if __name__ == '__main__':
...@@ -304,11 +304,12 @@ if __name__ == '__main__': ...@@ -304,11 +304,12 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后- # position = 左-右+、上+下-、前+后-
ursina_run(sim.bodies, SECONDS_PER_MONTH / 2, ursina_run(sim.bodies, SECONDS_PER_MONTH / 1,
position=(AU, AU * 5, -AU * 5), # position=(AU, AU * 5, -AU * 5),
position=(0, 0, -AU * 6),
cosmic_bg='', cosmic_bg='',
show_grid=False, show_grid=False,
# show_exit_button=False, # show_exit_button=False,
show_camera_info=False, # show_camera_info=False,
show_control_info=False, show_control_info=False,
timer_enabled=True) timer_enabled=True)
...@@ -346,6 +346,7 @@ def clear_trails(parent): ...@@ -346,6 +346,7 @@ def clear_trails(parent):
for entity, pos in parent.trails.items(): for entity, pos in parent.trails.items():
destroy(entity) destroy(entity)
parent.trails.clear() parent.trails.clear()
parent.body.clear_his_position()
if hasattr(parent, "trail_last_pos"): if hasattr(parent, "trail_last_pos"):
delattr(parent, "trail_last_pos") delattr(parent, "trail_last_pos")
if hasattr(parent, "last_trail"): if hasattr(parent, "last_trail"):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册