提交 934bf2dc 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 9ee3b138
...@@ -85,6 +85,12 @@ class Body(metaclass=ABCMeta): ...@@ -85,6 +85,12 @@ class Body(metaclass=ABCMeta):
self.show_name = show_name self.show_name = show_name
self.resolution = None
def set_resolution(self, value):
self.resolution = value
return self
@property @property
def init_position(self): def init_position(self):
""" """
...@@ -307,7 +313,7 @@ class Body(metaclass=ABCMeta): ...@@ -307,7 +313,7 @@ class Body(metaclass=ABCMeta):
def __repr__(self): def __repr__(self):
return '<%s(%s)> m=%.3e(kg), r|d=%.3e|%.3e(km), v=%.3e(km³), d=%.3e(kg/m³), p=[%.3e,%.3e,%.3e](km), v=%s(km/s)' % \ return '<%s(%s)> m=%.3e(kg), r|d=%.3e|%.3e(km), v=%.3e(km³), d=%.3e(kg/m³), p=[%.3e,%.3e,%.3e](km), v=%s(km/s)' % \
(self.name,self.__class__.__name__, self.mass, self.raduis, self.diameter, self.volume, self.density, (self.name, self.__class__.__name__, self.mass, self.raduis, self.diameter, self.volume, self.density,
self.position[0], self.position[1], self.position[2], self.velocity) self.position[0], self.position[1], self.position[2], self.velocity)
def ignore_gravity(self, body): def ignore_gravity(self, body):
......
...@@ -13,11 +13,18 @@ from sim_scenes.func import ursina_run ...@@ -13,11 +13,18 @@ from sim_scenes.func import ursina_run
if __name__ == '__main__': if __name__ == '__main__':
""" """
地球晚上模拟运行 地球晚上模拟运行
图片来源:
https://www.nasa.gov/mission_pages/NPP/news/earth-at-night.html
https://www.nasa.gov/sites/default/files/images/712130main_8246931247_e60f3c09fb_o.jpg
""" """
resolution = 500
bodies = [ bodies = [
Earth(texture="earth_at_night.jpg", Earth(texture="earth_at_night_hd.jpg",
init_position=[0, 0, 0], init_velocity=[0, 0, 0], init_position=[0, 0, 0], init_velocity=[0, 0, 0],
size_scale=100.0001, ignore_mass=True) size_scale=100, ignore_mass=True).set_resolution(resolution),
Earth(texture="earth_hd.jpg",
init_position=[0, 10, 0], init_velocity=[0, 0, 0],
size_scale=100, ignore_mass=True).set_resolution(resolution)
] ]
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
......
...@@ -110,7 +110,11 @@ class Planet(Entity): ...@@ -110,7 +110,11 @@ class Planet(Entity):
rotation = (90, 0, 0) rotation = (90, 0, 0)
else: else:
# 创建一个天体 # 创建一个天体
model = create_sphere(0.5, 32) subdivisions = 32
if self.body_view.body.resolution is not None:
subdivisions = self.body_view.body.resolution
model = create_sphere(0.5, subdivisions)
rotation = (0, 0, 0) rotation = (0, 0, 0)
UrsinaEvent.on_reset_subscription(self.on_reset) UrsinaEvent.on_reset_subscription(self.on_reset)
...@@ -147,7 +151,7 @@ class Planet(Entity): ...@@ -147,7 +151,7 @@ class Planet(Entity):
self.name_text = Text(self.body_view.body.name, scale=1, billboard=True, parent=self, self.name_text = Text(self.body_view.body.name, scale=1, billboard=True, parent=self,
font=UrsinaConfig.CN_FONT, background=True, font=UrsinaConfig.CN_FONT, background=True,
origin=(0, 0)) origin=(0, 0))
self.name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.5) self.name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.3)
# self.name_text.scale = self.scale # self.name_text.scale = self.scale
inverse_color = get_inverse_color(b_color) inverse_color = get_inverse_color(b_color)
self.name_text.color = color.rgba(inverse_color[0], inverse_color[1], inverse_color[2], 1) self.name_text.color = color.rgba(inverse_color[0], inverse_color[1], inverse_color[2], 1)
...@@ -378,7 +382,6 @@ class Planet(Entity): ...@@ -378,7 +382,6 @@ class Planet(Entity):
# self.ring = Entity(parent=self.planet, model='circle', texture=rings_texture, scale=3.5, # self.ring = Entity(parent=self.planet, model='circle', texture=rings_texture, scale=3.5,
# rotation=(self.ring_rotation_x, 0, 0), double_sided=True) # rotation=(self.ring_rotation_x, 0, 0), double_sided=True)
# 行星环偏移角度 # 行星环偏移角度
self.ring_rotation_x = 80 self.ring_rotation_x = 80
# 创建行星环 # 创建行星环
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册