提交 1b331a87 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 0ab2d9f7
...@@ -21,6 +21,7 @@ class Body(metaclass=ABCMeta): ...@@ -21,6 +21,7 @@ class Body(metaclass=ABCMeta):
def __init__(self, name, mass, init_position, init_velocity, rotate_angle=0, def __init__(self, name, mass, init_position, init_velocity, rotate_angle=0,
density=5e3, color=(125 / 255, 125 / 255, 125 / 255), density=5e3, color=(125 / 255, 125 / 255, 125 / 255),
text_color=None,
texture=None, size_scale=1.0, distance_scale=1.0, texture=None, size_scale=1.0, distance_scale=1.0,
rotation_speed=None, parent=None, ignore_mass=False, rotation_speed=None, parent=None, ignore_mass=False,
is_fixed_star=False, trail_color=None, show_name=False): is_fixed_star=False, trail_color=None, show_name=False):
...@@ -53,6 +54,7 @@ class Body(metaclass=ABCMeta): ...@@ -53,6 +54,7 @@ class Body(metaclass=ABCMeta):
self.name = name self.name = name
self.__mass = mass self.__mass = mass
self.text_color = text_color
# 是否忽略质量(如果为True,则不计算引力) # 是否忽略质量(如果为True,则不计算引力)
# TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) # TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨)
......
...@@ -26,7 +26,8 @@ class Earth(Body): ...@@ -26,7 +26,8 @@ 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],
texture="earth1.jpg", size_scale=1.0, distance_scale=1.0, color=(7, 0, 162), texture="earth1.jpg",text_color=None,
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,
parent=None): parent=None):
...@@ -37,7 +38,8 @@ class Earth(Body): ...@@ -37,7 +38,8 @@ class Earth(Body):
"init_velocity": init_velocity, "init_velocity": init_velocity,
"rotate_angle": rotate_angle, "rotate_angle": rotate_angle,
"density": 5507.85, "density": 5507.85,
"color": (7, 0, 162), "color": color,
"text_color": text_color,
"texture": texture, "texture": texture,
"size_scale": size_scale, "size_scale": size_scale,
"distance_scale": distance_scale, "distance_scale": distance_scale,
......
...@@ -19,13 +19,13 @@ if __name__ == '__main__': ...@@ -19,13 +19,13 @@ if __name__ == '__main__':
""" """
bodies = [ bodies = [
Sun(size_scale=5e1, texture="transparent.png"), # 太阳透明 Sun(size_scale=5e1, texture="transparent.png"), # 太阳透明
Earth(name="中国春天", size_scale=2e3, texture="earth_hd.jpg", Earth(name="中国春天", size_scale=6e3, texture="earth_hd.jpg", text_color=(0, 255, 0),
init_position=[-1 * AU, 0, 0], init_velocity=[0, 0, -29.79]), init_position=[-1 * AU, 0, 0], init_velocity=[0, 0, -29.79]),
Earth(name="中国夏天", size_scale=2e3, texture="earth_hd.jpg", Earth(name="中国夏天", size_scale=6e3, texture="earth_hd.jpg", text_color=(255, 0, 0),
init_position=[0, 0, -1 * AU], init_velocity=[29.79, 0, 0]), init_position=[0, 0, -1 * AU], init_velocity=[29.79, 0, 0]),
Earth(name="中国秋天", size_scale=2e3, texture="earth_hd.jpg", Earth(name="中国秋天", size_scale=6e3, texture="earth_hd.jpg", text_color=(255, 255, 0),
init_position=[1 * AU, 0, 0], init_velocity=[0, 0, 29.79]), init_position=[1 * AU, 0, 0], init_velocity=[0, 0, 29.79]),
Earth(name="中国冬天", size_scale=2e3, texture="earth_hd.jpg", Earth(name="中国冬天", size_scale=6e3, texture="earth_hd.jpg", text_color=(0, 255, 255),
init_position=[0, 0, 1 * AU], init_velocity=[-29.79, 0, 0]), init_position=[0, 0, 1 * AU], init_velocity=[-29.79, 0, 0]),
] ]
sun = bodies[0] sun = bodies[0]
...@@ -41,13 +41,14 @@ if __name__ == '__main__': ...@@ -41,13 +41,14 @@ if __name__ == '__main__':
# camera.forward = -10 * AU # camera.forward = -10 * AU
# # camera.x = camera.x - AU / 100 # # camera.x = camera.x - AU / 100
# camera.look_at(earth.planet) # camera.look_at(earth.planet)
earth_1.planet.rotation_y -= 205 # 春天 earth_1.planet.rotation_y += 115 # 春天
earth_2.planet.rotation_y -= 0 # 夏天 earth_2.planet.rotation_y += 15 # 夏天
earth_3.planet.rotation_y -= 100 # 秋天 earth_3.planet.rotation_y -= 80 # 秋天
earth_4.planet.rotation_y -= 175 # 冬天 earth_4.planet.rotation_y -= 145 # 冬天
camera.parent = sun.planet # camera.parent = sun.planet
camera.look_at(earth_2.planet) camera.look_at(earth_4.planet)
camera.rotation_z = 0
# camera.position=[0,0,0] # camera.position=[0,0,0]
pass pass
......
...@@ -26,6 +26,7 @@ def create_name_text(parent): ...@@ -26,6 +26,7 @@ def create_name_text(parent):
@param parent: @param parent:
@return: @return:
""" """
text_color = parent.body.text_color
b_color = parent.body_view.color b_color = parent.body_view.color
name_text = Text(parent.body_view.body.name, scale=1, billboard=True, parent=parent, name_text = Text(parent.body_view.body.name, scale=1, billboard=True, parent=parent,
font=UrsinaConfig.CN_FONT, background=True, font=UrsinaConfig.CN_FONT, background=True,
...@@ -33,8 +34,12 @@ def create_name_text(parent): ...@@ -33,8 +34,12 @@ def create_name_text(parent):
name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.3) name_text.background.color = color.rgba(b_color[0], b_color[1], b_color[2], 0.3)
name_text.resolution = 24 name_text.resolution = 24
# self.name_text.scale = self.scale # self.name_text.scale = self.scale
inverse_color = get_inverse_color(b_color) if text_color is None:
name_text.color = color.rgba(inverse_color[0], inverse_color[1], inverse_color[2], 1) text_color = get_inverse_color(b_color)
else:
text_color = (text_color[0]/255, text_color[1]/255, text_color[2]/255)
name_text.set_light_off()
name_text.color = color.rgba(text_color[0], text_color[1], text_color[2], 1)
parent.name_text = name_text parent.name_text = name_text
return name_text return name_text
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册