diff --git a/sim_scenes/fiction/stephenson_2_18.py b/sim_scenes/fiction/stephenson_2_18.py new file mode 100644 index 0000000000000000000000000000000000000000..68a9e342e08c7b35a1f1a7b5ca9ef11006900c0f --- /dev/null +++ b/sim_scenes/fiction/stephenson_2_18.py @@ -0,0 +1,47 @@ +# -*- coding:utf-8 -*- +# title :太阳和史蒂文森2-18 +# description :太阳和史蒂文森2-18 +# author :Python超人 +# date :2023-06-10 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +from bodies import Stephenson_2_18 +from bodies import Sun, Earth +from bodies.body import AU +from common.consts import SECONDS_PER_WEEK +from sim_scenes.func import ursina_run + +if __name__ == '__main__': + """ + 太阳和史蒂文森2-18 + """ + # 构建恒星天体对象 + SIZE_SCALE = 0.5 # 所有天体尺寸缩放保持一致 + # TODO: ignore_mass=True + # 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨) + bodies = [ + Earth(size_scale=SIZE_SCALE, ignore_mass=True, + init_position=[-2896.9165, 2896.9165, 0]), + Sun(size_scale=SIZE_SCALE, ignore_mass=True, + init_position=[-316397.06, 316397.06, 386345.72]), # 太阳 + Stephenson_2_18(size_scale=SIZE_SCALE, color=(28, 2, 1), ignore_mass=True, + init_position=[-10e+08, 6.802537e+08, 8.234898e+08]) # 史蒂文森2-18 质量倍数 40.0 半径倍数 2150 + ] + + # 循环为每个恒星的初始位置进行赋值,方便演示 + for idx, body in enumerate(bodies): + body.rotation_speed /= 10 # 恒星的旋转速度减小10倍 + if body.is_fixed_star: + body.light_on = False # 关闭灯光效果 + # 所有天体的初始速度为 0 + body.init_velocity = [0, 0, 0] + + # 使用 ursina 查看的运行效果 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + # M:摄像机移动加速 N:摄像机移动减速 + # position = (左-右+、上+下-、前+后-) + ursina_run(bodies, SECONDS_PER_WEEK, + position=(0, 30000, -AU / 500), + show_grid=False, + show_name=True, bg_music="sounds/universe_03.mp3") diff --git a/sim_scenes/solar_system/sun_future_evolution.py b/sim_scenes/solar_system/sun_future_evolution.py index 3bf48794f6e4b3346ede1810660e39fb5464a385..ef95a6bb38e578dfa95d0ba0f8e27f61555e915c 100644 --- a/sim_scenes/solar_system/sun_future_evolution.py +++ b/sim_scenes/solar_system/sun_future_evolution.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- -# title :亿万年后太阳演化模拟 -# description :亿万年后太阳演化模拟(展示的效果为太阳系真实的距离) +# title :太阳系场景模拟1 +# description :太阳系场景模拟(展示的效果为太阳系真实的距离) # author :Python超人 # date :2023-02-11 # link :https://gitcode.net/pythoncr/ @@ -8,8 +8,9 @@ # ============================================================================== 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, camera_look_at +from sim_scenes.func import mayavi_run, ursina_run from simulators.ursina.entities.body_timer import TimeData +from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_event import UrsinaEvent if __name__ == '__main__': @@ -21,40 +22,44 @@ if __name__ == '__main__': # ===================================================================== # 以下展示的效果为太阳系真实的距离 # 由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大 - sun = Sun(name="太阳", size_scale=0.6e2) # 太阳一开始放大 60 倍,距离保持不变 + sun = Sun(name="太阳", size_scale=0.8e2) # 太阳放大 80 倍,距离保持不变 bodies = [ sun, - Mercury(name="水星", size_scale=2e3), # 水星放大 2000 倍,距离保持不变 - Venus(name="金星", size_scale=2e3), # 金星放大 2000 倍,距离保持不变 - Earth(name="地球", size_scale=2e3), # 地球放大 2000 倍,距离保持不变 - Mars(name="火星", size_scale=2e3), # 火星放大 2000 倍,距离保持不变 - Jupiter(name="木星", size_scale=0.4e3), # 木星放大 400 倍,距离保持不变 - Saturn(name="土星", size_scale=0.4e3), # 土星放大 400 倍,距离保持不变 - Uranus(name="天王星", size_scale=0.4e3), # 天王星放大 400 倍,距离保持不变 - Neptune(name="海王星", size_scale=0.5e3), # 海王星放大 500 倍,距离保持不变 - Pluto(name="冥王星", size_scale=5e3), # 冥王星放大 5000 倍,距离保持不变(从太阳系的行星中排除) + Mercury(name="水星", size_scale=4e3), # 水星放大 4000 倍,距离保持不变 + Venus(name="金星", size_scale=4e3), # 金星放大 4000 倍,距离保持不变 + Earth(name="地球", size_scale=4e3), # 地球放大 4000 倍,距离保持不变 + Mars(name="火星", size_scale=4e3), # 火星放大 4000 倍,距离保持不变 + # Asteroids(name="小行星群", size_scale=3.2e2, + # parent=sun), # 小行星群模拟(仅 ursina 模拟器支持) + Jupiter(name="木星", size_scale=0.8e3), # 木星放大 800 倍,距离保持不变 + Saturn(name="土星", size_scale=0.8e3), # 土星放大 800 倍,距离保持不变 + Uranus(name="天王星", size_scale=0.8e3), # 天王星放大 800 倍,距离保持不变 + Neptune(name="海王星", size_scale=1e3), # 海王星放大 1000 倍,距离保持不变 + Pluto(name="冥王星", size_scale=10e3), # 冥王星放大 10000 倍,距离保持不变(从太阳系的行星中排除) ] - - def on_ready(): - # 运行前触发 - # 摄像机看向太阳 - camera_look_at(sun) - + # 循环为每个恒星的初始位置进行赋值,方便演示 + for idx, body in enumerate(bodies): + body.rotation_speed /= 200 # 恒星的旋转速度减小10倍 def on_timer_changed(time_data: TimeData): - sun.planet.init_scale = sun.planet.init_scale + 0.1 + sun.planet.init_scale = sun.planet.init_scale + 0.2 + + # + # UrsinaConfig.trail_type = "line" # 订阅事件后,上面的函数功能才会起作用 # 运行前会触发 on_ready - UrsinaEvent.on_ready_subscription(on_ready) + # UrsinaEvent.on_ready_subscription(on_ready) # 运行中,每时每刻都会触发 on_timer_changed UrsinaEvent.on_timer_changed_subscription(on_timer_changed) # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 10 * AU, -10 * AU), + ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), timer_enabled=True, + show_grid=False, + # show_trail=True, bg_music="sounds/interstellar.mp3")