From 1b331a876c54930c8d93dab33c33dafeb46c67ef Mon Sep 17 00:00:00 2001 From: march3 Date: Sun, 16 Apr 2023 22:15:34 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bodies/body.py | 2 ++ bodies/earth.py | 6 ++++-- sim_scenes/science/four_seasons.py | 21 +++++++++++---------- simulators/ursina/entities/entity_utils.py | 9 +++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bodies/body.py b/bodies/body.py index 0467db2..3811f40 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -21,6 +21,7 @@ class Body(metaclass=ABCMeta): def __init__(self, name, mass, init_position, init_velocity, rotate_angle=0, density=5e3, color=(125 / 255, 125 / 255, 125 / 255), + text_color=None, texture=None, size_scale=1.0, distance_scale=1.0, rotation_speed=None, parent=None, ignore_mass=False, is_fixed_star=False, trail_color=None, show_name=False): @@ -53,6 +54,7 @@ class Body(metaclass=ABCMeta): self.name = name self.__mass = mass + self.text_color = text_color # 是否忽略质量(如果为True,则不计算引力) # TODO: 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) diff --git a/bodies/earth.py b/bodies/earth.py index dedf787..009a068 100644 --- a/bodies/earth.py +++ b/bodies/earth.py @@ -26,7 +26,8 @@ class Earth(Body): def __init__(self, name="地球", mass=5.97237e24, rotate_angle=23.44, init_position=[0, 0, 1 * AU], 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, trail_color=None, show_name=False, parent=None): @@ -37,7 +38,8 @@ class Earth(Body): "init_velocity": init_velocity, "rotate_angle": rotate_angle, "density": 5507.85, - "color": (7, 0, 162), + "color": color, + "text_color": text_color, "texture": texture, "size_scale": size_scale, "distance_scale": distance_scale, diff --git a/sim_scenes/science/four_seasons.py b/sim_scenes/science/four_seasons.py index 77b7cda..b3b6f3c 100644 --- a/sim_scenes/science/four_seasons.py +++ b/sim_scenes/science/four_seasons.py @@ -19,13 +19,13 @@ if __name__ == '__main__': """ bodies = [ 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]), - 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]), - 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]), - 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]), ] sun = bodies[0] @@ -41,13 +41,14 @@ if __name__ == '__main__': # camera.forward = -10 * AU # # camera.x = camera.x - AU / 100 # camera.look_at(earth.planet) - earth_1.planet.rotation_y -= 205 # 春天 - earth_2.planet.rotation_y -= 0 # 夏天 - earth_3.planet.rotation_y -= 100 # 秋天 - earth_4.planet.rotation_y -= 175 # 冬天 + earth_1.planet.rotation_y += 115 # 春天 + earth_2.planet.rotation_y += 15 # 夏天 + earth_3.planet.rotation_y -= 80 # 秋天 + earth_4.planet.rotation_y -= 145 # 冬天 - camera.parent = sun.planet - camera.look_at(earth_2.planet) + # camera.parent = sun.planet + camera.look_at(earth_4.planet) + camera.rotation_z = 0 # camera.position=[0,0,0] pass diff --git a/simulators/ursina/entities/entity_utils.py b/simulators/ursina/entities/entity_utils.py index 369609c..152f3e0 100644 --- a/simulators/ursina/entities/entity_utils.py +++ b/simulators/ursina/entities/entity_utils.py @@ -26,6 +26,7 @@ def create_name_text(parent): @param parent: @return: """ + text_color = parent.body.text_color b_color = parent.body_view.color name_text = Text(parent.body_view.body.name, scale=1, billboard=True, parent=parent, font=UrsinaConfig.CN_FONT, background=True, @@ -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.resolution = 24 # self.name_text.scale = self.scale - inverse_color = get_inverse_color(b_color) - name_text.color = color.rgba(inverse_color[0], inverse_color[1], inverse_color[2], 1) + if text_color is None: + 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 return name_text -- GitLab