From d781ef11dd9c5fcb1d51ef2abeca1b7450983e7f Mon Sep 17 00:00:00 2001 From: march3 Date: Mon, 27 Nov 2023 12:00:04 +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 --- common/func.py | 3 ++- sim_scenes/fiction/earth_orbit_stopped.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/func.py b/common/func.py index 7141d71..bf3d6ff 100644 --- a/common/func.py +++ b/common/func.py @@ -146,7 +146,7 @@ def get_acceleration_info(acceleration): acc_value = acceleration acc_m = acc_value * 1000 # 加速度的值(m/s²) - + # "\n\n当前速度:%s km/s" % "{:.3f}".format(velocity).rjust(6, "0") if acc_m >= 0.01: acc_info = "%.2f m/s²" % (acc_m) elif acc_m >= 0.00001: @@ -155,6 +155,7 @@ def get_acceleration_info(acceleration): # acc_info = "%.2fμm/s²" % (acc_m * 1000 * 1000) else: acc_info = "0 m/s²" + return acc_info diff --git a/sim_scenes/fiction/earth_orbit_stopped.py b/sim_scenes/fiction/earth_orbit_stopped.py index af9cdd4..1a93df7 100644 --- a/sim_scenes/fiction/earth_orbit_stopped.py +++ b/sim_scenes/fiction/earth_orbit_stopped.py @@ -92,8 +92,8 @@ class EarthOrbitStoppedSim(UniverseSimScenes): replace("${velocity}", "0"). \ replace("${acceleration}", "0") - sky = create_sphere_sky(scale=10000) - sky.rotation_y = 180 + self.sky = create_sphere_sky(scale=10000) + self.sky.rotation_y = 180 # sky.rotation_x = 20 # sky.rotation_z = -65 @@ -103,9 +103,10 @@ class EarthOrbitStoppedSim(UniverseSimScenes): self.venus_orbit_line = create_orbit_line(self.sun, self.venus, thickness=3, alpha=0.3) def show_message(self, msg): - ControlUI.current_ui.show_message(msg, font="fonts/DroidSansFallback.ttf", close_time=-1) + ControlUI.current_ui.show_message(msg, font="fonts/DroidSansFallback.ttf", close_time=6) def on_timer_changed(self, time_data: TimeData): + self.sky.rotation_z += 0.005 # 摄像机时时刻刻看向地球 camera_look_at(self.earth, rotation_z=0) # 获取地球当前的位置,让摄像机跟随地球 @@ -121,13 +122,13 @@ class EarthOrbitStoppedSim(UniverseSimScenes): distance = distance - self.sun.radius - self.earth.radius if distance > 100000000: - distance_str = "%s亿" % round(distance / 100000000.0, 2) + distance_str = "%.2f亿" % round(distance / 100000000.0, 2) # elif distance > 10000000: # distance_str = "%s千万" % round(distance / 10000000.0, 2) # elif distance > 1000000: # distance_str = "%s百万" % round(distance / 1000000.0, 2) elif distance > 10000: - distance_str = "%s万" % round(distance / 10000.0, 2) + distance_str = "%.2f万" % round(distance / 10000.0, 2) else: distance_str = round(distance, 2) @@ -138,7 +139,7 @@ class EarthOrbitStoppedSim(UniverseSimScenes): self.text_panel.text = self.arrived_info. \ replace("${distance}", "0 km"). \ replace("${acceleration}", "%s" % acceleration_info). \ - replace("${velocity}", "%s km/s" % round(velocity, 2)) \ + replace("${velocity}", "%.2f km/s" % round(velocity, 2)) \ + "\n\n" + msg self.show_message(msg) application.pause() @@ -216,7 +217,7 @@ class EarthOrbitStoppedSim(UniverseSimScenes): self.text_panel.text = self.arrived_info. \ replace("${distance}", "%s km" % distance_str). \ replace("${acceleration}", "%s" % acceleration_info). \ - replace("${velocity}", "%s km/s" % round(velocity, 2)) + replace("${velocity}", "%.2f km/s" % round(velocity, 2)) if __name__ == '__main__': @@ -248,7 +249,8 @@ if __name__ == '__main__': # 订阅事件后,上面的函数功能才会起作用 # 运行中,每时每刻都会触发 on_timer_changed UrsinaEvent.on_timer_changed_subscription(sim.on_timer_changed) - UniverseSimScenes.set_window_size((1400, 700)) + # UniverseSimScenes.set_window_size((1400, 700)) + UniverseSimScenes.set_window_size((1920, 1079), False) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- -- GitLab