diff --git a/scenes/gravity_slingshot.py b/scenes/gravity_slingshot.py new file mode 100644 index 0000000000000000000000000000000000000000..621774b67318f63cb38f52b2b8981c12f9137669 --- /dev/null +++ b/scenes/gravity_slingshot.py @@ -0,0 +1,35 @@ +# -*- coding:utf-8 -*- +# title :引力弹弓模拟演示 +# description :引力弹弓模拟演示 +# author :Python超人 +# date :2023-02-11 +# link :https://gitcode.net/pythoncr/ +# python_version :3.8 +# ============================================================================== +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 scenes.func import mayavi_run, ursina_run +from bodies.body import AU + +if __name__ == '__main__': + """ + 太阳、地球 + """ + bodies = [ + Sun(size_scale=2e1), # 太阳放大 20 倍 + Earth(size_scale=1e3, # 地球放大 1000 倍 + init_position=[0, -3 * AU, 0], # 地球距离太阳 3 个天文单位 + # TODO: 尝试调整朝向太阳的速度,取值 33、38、50 或者其他 + # init_velocity=[0, 33, -1], + init_velocity=[0, 38, -1], # 朝向太阳的速度为 38km/s,-1 km/s 是为了防止地球正面对着太阳冲去 + # init_velocity=[0, 50, -1], + ), + ] + + # 使用 mayavi 查看的运行效果 + # mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45) + + # 使用 ursina 查看的运行效果 + # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 + ursina_run(bodies, SECONDS_PER_MONTH, position=(0, AU, -3 * AU)) diff --git a/scenes/solar_system_1.py b/scenes/solar_system_1.py index 981bc2047df4b04fd0812bc0dedda2b406e3b0ca..1456cfd305a287b029c47b3c6d295ea5e2407d33 100644 --- a/scenes/solar_system_1.py +++ b/scenes/solar_system_1.py @@ -40,4 +40,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU)) diff --git a/scenes/solar_system_2.py b/scenes/solar_system_2.py index c6923a522631484d3caaa7d36dcc78aa2f1d4f36..a5d8c912e70db10c5508d238ea7bac2c6e68b9bb 100644 --- a/scenes/solar_system_2.py +++ b/scenes/solar_system_2.py @@ -43,4 +43,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU)) diff --git a/scenes/sun_earth.py b/scenes/sun_earth.py index 62266f38be91076046f490ff755db6536e7c36f2..eea967243b571d506985479193c744a33763be5b 100644 --- a/scenes/sun_earth.py +++ b/scenes/sun_earth.py @@ -24,4 +24,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -3 * AU)) diff --git a/scenes/sun_earth_jupiter.py b/scenes/sun_earth_jupiter.py index 5a8f480affba8a31f5c934403739bddcdefc34c9..71be10b76251f10fdad45b11be45cdf70509d670 100644 --- a/scenes/sun_earth_jupiter.py +++ b/scenes/sun_earth_jupiter.py @@ -25,4 +25,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -3 * AU)) diff --git a/scenes/sun_earth_moon.py b/scenes/sun_earth_moon.py index 157153235957e500a29bde60d4d9529b02c269da..6a379dfe20202a855f17b89d42d076ccab043f30 100644 --- a/scenes/sun_earth_moon.py +++ b/scenes/sun_earth_moon.py @@ -42,6 +42,7 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- # position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程 + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, 0)) # 使用 mayavi 查看的运行效果 diff --git a/scenes/three_body_01.py b/scenes/three_body_01.py index 9c19a41db9b9df4567a7d91b2c1db26e52509707..bc30401c0501428028fde38e0d8c4d4c53880869 100644 --- a/scenes/three_body_01.py +++ b/scenes/three_body_01.py @@ -33,4 +33,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_DAY, position=(3 * AU, AU, -4 * AU)) \ No newline at end of file diff --git a/scenes/three_body_03.py b/scenes/three_body_03.py index 72d4644fc213fda80657c9895277a00be7d8509c..92d9e07b50c0c3fddcb394bf5405860ac7e37d74 100644 --- a/scenes/three_body_03.py +++ b/scenes/three_body_03.py @@ -58,4 +58,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_YEAR, position=(3 * AU, 3 * AU, -20 * AU)) diff --git a/scenes/two_body_01.py b/scenes/two_body_01.py index 03f1f7866dae294a18d38c7472649fed6456704d..1a05490f820bd47d3d81135265373105d4ac8d86 100644 --- a/scenes/two_body_01.py +++ b/scenes/two_body_01.py @@ -32,4 +32,5 @@ if __name__ == '__main__': # 使用 ursina 查看的运行效果 # position = 左-右+、上+下-、前+后- + # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -5 * AU)) \ No newline at end of file diff --git a/simulators/ursina/ursina_ui.py b/simulators/ursina/ursina_ui.py index 391411988cf2b2f05cb11ca713556b59e001dcb4..7f1062c07ef20d1ba3dfb0de1d030bcae822f3c4 100644 --- a/simulators/ursina/ursina_ui.py +++ b/simulators/ursina/ursina_ui.py @@ -43,7 +43,7 @@ class UrsinaUI: self.on_off_switch = SwithButton((self.pause_button_text, self.start_button_text), default=self.start_button_text, - tooltips=('暂停', '运行')) + tooltips=('暂停(P)', '运行(P)')) self.on_off_switch.selected_color = color.red self.sec_per_time_switch = SwithButton(("默认", "天", "周", "月", "年", "十年", "百年"), @@ -58,8 +58,8 @@ class UrsinaUI: tooltips=('天体运行无轨迹', '天体运行有拖尾轨迹')) self.on_off_trail.on_value_changed = self.on_off_trail_changed - self.point_button = UiButton(text='寻找', on_click=self.on_searching_bodies_click) - self.reset_button = UiButton(text='重置', on_click=self.on_reset_button_click) + self.point_button = UiButton(text='寻找天体(Y)', on_click=self.on_searching_bodies_click) + self.reset_button = UiButton(text='重新开始(O)', on_click=self.on_reset_button_click) # button1 = Button(text='Button 1', scale=(0.1, 0.1), position=(-0.1, 0)) # button2 = Button(text='Button 2', scale=(0.1, 0.1), position=(0.1, 0)) @@ -327,6 +327,40 @@ class UrsinaUI: self.wp.enabled = not self.wp.enabled elif key == 'left mouse down': print(key) + elif key == 'y': # 寻找天体 + if hasattr(self, "bodies_button_list"): + if self.bodies_button_list.enabled: + self.bodies_button_list.enabled = False + destroy(self.bodies_button_list) + return + self.on_searching_bodies_click() + elif key == 'o': # 重新开始 + self.on_reset_button_click() + elif key == 'i': # 拖尾开关 + if self.on_off_trail.value == self.trail_button_text: + self.on_off_trail.value = self.no_trail_button_text + else: + self.on_off_trail.value = self.trail_button_text + self.on_off_trail_changed() + elif key == 'p': # 开始、暂停 + if self.on_off_switch.value == self.pause_button_text: + self.on_off_switch.value = self.start_button_text + else: + self.on_off_switch.value = self.pause_button_text + self.on_off_switch_changed() + elif key == '+' or key == "= up": + run_speed_factor = self.slider_run_speed_factor.value + self.slider_run_speed_factor.step * 50 + if run_speed_factor > self.slider_run_speed_factor.max: + run_speed_factor = self.slider_run_speed_factor.max + self.slider_run_speed_factor.value = run_speed_factor + self.slider_run_speed_factor.knob.drop() + elif key == '-' or key == "- up": + run_speed_factor = self.slider_run_speed_factor.value - self.slider_run_speed_factor.step * 50 + if run_speed_factor < self.slider_run_speed_factor.min: + run_speed_factor = self.slider_run_speed_factor.min + self.slider_run_speed_factor.value = run_speed_factor + self.slider_run_speed_factor.knob.drop() + # UrsinaConfig.run_speed_factor *= 2 # application.paused = not application.paused # Pause/unpause the game. # elif key == 'tab': # # application.time_scale 属性控制游戏时间流逝的速度。