From c10acbec3451ad533009d3fdd122bc1d94ae6c1c Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 6 Oct 2023 18:13:16 +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/asteroid.py | 4 ++++ common/win_pos.py | 12 ++++++++++++ sim_scenes/func.py | 8 ++++++++ sim_scenes/solar_system/solar_system_2.py | 16 ++++++++++++++-- sim_scenes/solar_system/solar_system_4.py | 16 +++++++++++++++- sim_scenes/wonders/sun_earth_moon.py | 23 +++++++++++++++++++++-- 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/bodies/asteroid.py b/bodies/asteroid.py index 0324fa8..351a2f0 100644 --- a/bodies/asteroid.py +++ b/bodies/asteroid.py @@ -47,6 +47,10 @@ class Asteroid(Body): def show_trail(self): return False + @show_trail.setter + def show_trail(self, value): + self.__show_trail = value + def ignore_gravity_with(self, body): """ 是否忽略指定天体的引力 diff --git a/common/win_pos.py b/common/win_pos.py index d867edf..b509c96 100644 --- a/common/win_pos.py +++ b/common/win_pos.py @@ -84,10 +84,22 @@ Area.rect.y : {y} print("Pycharm 窗口", rect) +def set_universe_win_pos(): + rect = (183, 70, 1536, 863) + r = 1.25 + rect = (int(rect[0]/r),int(rect[1]/r),int((rect[2]+rect[0])/r),int((rect[3]+rect[1])/r)) + # Area.rect.h: 863 + # Area.rect.w: 1536 + # Area.rect.x: 183 + # Area.rect.y: 70 + set_win_pos('宇宙模拟器(universe sim)', rect) + + if __name__ == '__main__': # 使用方法: # 1、运行 win_pos.py,找到 EV录屏 区域 -> EV录屏 (183, 70, 1536, 863) set_pycharm_win_pos() + # set_universe_win_pos() # 2、打开 C:\Users\Administrator\AppData\Local\EVCapture\conf\Admin.conf # 修改: # Area.rect.h : 863 diff --git a/sim_scenes/func.py b/sim_scenes/func.py index 312e6ea..9df0183 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -663,6 +663,14 @@ def speed_smooth_adjust_test(): plt.show() +def create_sphere_sky(texture="bg_pan.jpg", scale=8000): + from common.image_utils import find_texture + from simulators.ursina.entities.sphere_sky import SphereSky + sky_texture = find_texture(texture, None) + if sky_texture is not None: + SphereSky(texture=sky_texture).scale = scale + + if __name__ == '__main__': # from bodies import Sun, Earth # diff --git a/sim_scenes/solar_system/solar_system_2.py b/sim_scenes/solar_system/solar_system_2.py index bccf083..2e54100 100644 --- a/sim_scenes/solar_system/solar_system_2.py +++ b/sim_scenes/solar_system/solar_system_2.py @@ -8,7 +8,8 @@ # ============================================================================== from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroids from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH, SECONDS_PER_YEAR, AU -from sim_scenes.func import mayavi_run, ursina_run +from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky +from simulators.ursina.ursina_event import UrsinaEvent if __name__ == '__main__': # 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿) @@ -37,8 +38,19 @@ if __name__ == '__main__': Pluto(size_scale=10e3, distance_scale=0.23), # 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除) ] # endregion + def on_ready(): + """ + 事件绑定后,模拟器运行前会触发 + @return: + """ + # 创建天空 + create_sphere_sky(scale=8000) + # 运行前会触发 on_ready + UrsinaEvent.on_ready_subscription(on_ready) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), show_grid=False) + ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), + cosmic_bg='', + show_grid=False) diff --git a/sim_scenes/solar_system/solar_system_4.py b/sim_scenes/solar_system/solar_system_4.py index d4648c8..5218ae9 100644 --- a/sim_scenes/solar_system/solar_system_4.py +++ b/sim_scenes/solar_system/solar_system_4.py @@ -8,9 +8,10 @@ # ============================================================================== from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Moon, Asteroids from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, AU -from sim_scenes.func import mayavi_run, ursina_run +from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky import math from common.consts import G +from simulators.ursina.ursina_event import UrsinaEvent def get_velocity(mass, distance, velocity, target_distance): @@ -86,9 +87,22 @@ if __name__ == '__main__': body.init_velocity = init_velocity body_index += 1 + # def on_ready(): + # """ + # 事件绑定后,模拟器运行前会触发 + # @return: + # """ + # # 创建天空 + # create_sphere_sky(scale=8000) + # + # # 运行前会触发 on_ready + # UrsinaEvent.on_ready_subscription(on_ready) + # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), show_trail=True, # 运行轨迹拖尾效果(通过快捷键 I 控制开关) + show_grid=False, + # cosmic_bg='', bg_music="sounds/interstellar.mp3") diff --git a/sim_scenes/wonders/sun_earth_moon.py b/sim_scenes/wonders/sun_earth_moon.py index ee73202..82a8d93 100644 --- a/sim_scenes/wonders/sun_earth_moon.py +++ b/sim_scenes/wonders/sun_earth_moon.py @@ -8,7 +8,7 @@ # ============================================================================== from bodies import Sun, Earth, Moon from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH -from sim_scenes.func import mayavi_run, ursina_run, camera_look_at +from sim_scenes.func import mayavi_run, ursina_run, camera_look_at, create_sphere_sky from bodies.body import AU from simulators.ursina.ursina_event import UrsinaEvent @@ -32,6 +32,7 @@ if __name__ == '__main__': # moon_pos, moon_vel = [-384400, 0, 0], [EARTH_INIT_VELOCITY, 0, -1.03] moon = Moon(init_position=moon_pos, # 距地距离约: 363104 至 405696 km init_velocity=moon_vel, + rotation_speed=0.40, size_scale=2e1) # 月球放大 20 倍,距离保持不变 bodies = [ sun, @@ -42,6 +43,18 @@ if __name__ == '__main__': ] + def on_ready(): + """ + 事件绑定后,模拟器运行前会触发 + @return: + """ + # 运行前触发 + # 创建天空 + create_sphere_sky(scale=8000) + + moon.planet.rotation_y = 90 + + def on_timer_changed(time_data): camera_look_at(moon, rotation_z=0) @@ -49,9 +62,15 @@ if __name__ == '__main__': # 订阅事件后,上面的函数功能才会起作用 # 运行中,每时每刻都会触发 on_timer_changed UrsinaEvent.on_timer_changed_subscription(on_timer_changed) + # 运行前会触发 on_ready + UrsinaEvent.on_ready_subscription(on_ready) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- # position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程 - ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, 0), show_timer=True) + ursina_run(bodies, SECONDS_PER_DAY, + position=(0, 0, 0), + show_grid=False, + cosmic_bg='', + show_timer=True) -- GitLab