diff --git a/sim_scenes/sci_pop/sun_earth_moon.py b/sim_scenes/sci_pop/sun_earth_moon.py index 32f531d1278c9f5b0ca569cac4e20baf46c47b32..78d5c3164e8f1ae0a83edd8e0bc775294779137e 100644 --- a/sim_scenes/sci_pop/sun_earth_moon.py +++ b/sim_scenes/sci_pop/sun_earth_moon.py @@ -32,13 +32,15 @@ class SunEarthMoonSim(UniverseSimScenes): self.bodies = None self.orbit_lines = [] self.run_finished = False + # 地球自转一圈是23小时56分4秒,公转一圈是365天6小时9分9秒 365.25 + self.earth_revolution_days = 365.25 + (9 * 60 + 9) / 60 / 60 / 24 def build_bodies(self): # region 构建太阳系 self.sun = Sun(size_scale=6e1, texture="sun_light.jpg") - self.moon = Moon(size_scale=18e2) - self.earth = Earth(size_scale=9e2, show_trail=False) - self.earth_start = Earth(size_scale=9e2, show_trail=False, rotation_speed=0) + self.moon = Moon(size_scale=22e2) + self.earth = Earth(size_scale=10e2, show_trail=False) + self.earth_start = Earth(size_scale=9.5e2, show_trail=False, rotation_speed=0) self.bodies = [self.sun, self.earth, self.moon, self.earth_start] @@ -63,34 +65,61 @@ class SunEarthMoonSim(UniverseSimScenes): @return: """ if self.run_finished: + # self.earth.planet.rotation_y = self.earth.planet.last_rotation_y + # self.moon.planet.rotation_y = self.moon.planet.last_rotation_y + # self.sun.planet.rotation_y = self.sun.planet.last_rotation_y return - dt = time_data.get_datetime(self.start_time) - if dt.year == 2025: + from ursina import distance + if time_data.total_days >= self.earth_revolution_days: self.run_finished = True - self.earth.rotation_speed = 0 + # self.earth.planet.rotation_speed = 0 + # self.moon.planet.rotation_speed = 0 + # self.sun.planet.rotation_speed = 0 + # + # self.earth.planet.last_rotation_y = self.earth.planet.rotation_y + # self.moon.planet.last_rotation_y = self.moon.planet.rotation_y + # self.sun.planet.last_rotation_y = self.sun.planet.rotation_y + + UrsinaConfig.run_speed_factor = 0.00001 * 24 + self.update_text_panel(time_data) return - if dt.month < 11: - UrsinaConfig.run_speed_factor = 200 - elif UrsinaConfig.run_speed_factor > 20: - UrsinaConfig.run_speed_factor = 20 + dt = time_data.get_datetime(self.start_time) + # if dt.year == self.current_year + 1: + + if dt.month < 12: + UrsinaConfig.run_speed_factor = 200 * 24 + elif UrsinaConfig.run_speed_factor > 20 * 24: + UrsinaConfig.run_speed_factor = 20 * 24 if dt.month >= 12 and dt.day >= 31: - UrsinaConfig.run_speed_factor -= 0.1 - elif dt.month >= 12 and dt.day >= 28 and UrsinaConfig.run_speed_factor >= 1.1: - UrsinaConfig.run_speed_factor -= 0.8 + if dt.hour > 20: + UrsinaConfig.run_speed_factor -= 0.00001 * 24 + if UrsinaConfig.run_speed_factor < 0.00001 * 24: + UrsinaConfig.run_speed_factor = 0.00001 * 24 + else: + UrsinaConfig.run_speed_factor -= 0.00001 * 24 + + elif dt.month >= 12 and dt.day >= 28 and UrsinaConfig.run_speed_factor >= 1.1 * 24: + UrsinaConfig.run_speed_factor -= 0.65 * 24 # elif dt.month >= 12 :#and dt.day > 20: # UrsinaConfig.run_speed_factor -= 1 - if UrsinaConfig.run_speed_factor < 0.1: - UrsinaConfig.run_speed_factor = 0.1 - UrsinaConfig.run_speed_factor = round(UrsinaConfig.run_speed_factor, 2) self.set_bodies_position(time_data) - self.update_text_panel(dt) + + self.update_text_panel(time_data) + + # if dt.month >= 12: + # dd = distance(self.earth.position, self.earth_start.position) + # # 225000388 + # if dd < 1000000: + # self.run_finished = True + # self.earth.planet.rotation_speed = 0 + # return def create_orbit_line(self, center_body, body, start_time, alpha=0.2): import math @@ -148,7 +177,7 @@ class SunEarthMoonSim(UniverseSimScenes): # camera_move_update() # camera_move_to_target_update() - def show_clock(self, dt): + def show_clock(self, time_data): """ 显示时钟 @param dt: 时间 datetime @@ -158,30 +187,42 @@ class SunEarthMoonSim(UniverseSimScenes): # position, origin = (0, .25), (0, 0), # else: from ursina import window + + total_days = round(time_data.total_days, 2) + if total_days > self.earth_revolution_days: + total_days = self.earth_revolution_days + seconds = self.earth_revolution_days * 24 * 60 * 60 + time_data = TimeData(seconds, "seconds", seconds) + + dt = time_data.get_datetime(self.start_time) + aspect_ratio = window.aspect_ratio position, origin = (0.5 * aspect_ratio - 0.15, -0.45), (-0.05, 0.1), - ControlUI.current_ui.show_message(dt.strftime('%Y-%m-%d'), - position=position, - origin=origin, - # font="verdana.ttf", - font="fonts/Digital-7Mono.TTF", - font_scale=2, - font_color=(0, 255, 0), - close_time=-1) - - self.text_panel.text = "时间:\n" + dt.strftime('%Y-%m-%d %H:%M') + "\n" + \ - "运行速度:" + str(UrsinaConfig.run_speed_factor) + "\n" - - def update_text_panel(self, dt): + # ControlUI.current_ui.show_message(dt.strftime('%Y-%m-%d'), + # position=position, + # origin=origin, + # # font="verdana.ttf", + # font="fonts/Digital-7Mono.TTF", + # font_scale=2, + # font_color=(0, 255, 0), + # close_time=-1) + + self.text_panel.text = "\n日期时间:\n" + dt.strftime('%Y-%m-%d %H:%M') + "\n\n" + \ + "天数:" + str(round(total_days, 3)) + # "运行速度:" + str(UrsinaConfig.run_speed_factor) + "\n" + \ + # "天数:" + str(round(total_days, 3)) + + def update_text_panel(self, time_data): """ 更新文字信息面板 @param d_sun: @return: """ + # panel_text = "时间" #"\n\n当前速度:%s km/s" % "{:.3f}".format(velocity).rjust(6, "0") # # self.text_panel.text = panel_text - self.show_clock(dt) + self.show_clock(time_data) def on_ready(self): """ @@ -205,10 +246,11 @@ class SunEarthMoonSim(UniverseSimScenes): # self.text_panel = create_text_panel(font="fonts/sanjixiaozhuanti.ttf", font_scale=1.5) self.text_panel = create_text_panel(font="fonts/DroidSansFallback.ttf", font_scale=1.3) - def run(self, start_time='2024-01-01 00:00:00'): + def run(self, start_time='2023-01-01 00:00:00'): self.build_bodies() from astropy.time import Time from datetime import datetime + self.current_year = int(start_time[0:4]) start_time = Time(datetime.strptime(start_time + '+0800', '%Y-%m-%d %H:%M:%S%z'), format='datetime') @@ -220,7 +262,7 @@ class SunEarthMoonSim(UniverseSimScenes): # init_bodies_reality_pos_vels(self.bodies, start_time) self.start_time = start_time ursina_run(self.bodies, - SECONDS_PER_DAY, + SECONDS_PER_DAY / 24, position=(0, 3.5 * AU, -AU), gravity_works=False, cosmic_bg='',