提交 8e147141 编写于 作者: 三月三net's avatar 三月三net

太阳系三体模拟器

上级 f377c0c6
# -*- 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))
......@@ -40,4 +40,5 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# position = 左-右+、上+下-、前+后-
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU))
......@@ -43,4 +43,5 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# position = 左-右+、上+下-、前+后-
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU))
......@@ -24,4 +24,5 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# position = 左-右+、上+下-、前+后-
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -3 * AU))
......@@ -25,4 +25,5 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# position = 左-右+、上+下-、前+后-
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -3 * AU))
......@@ -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 查看的运行效果
......
......@@ -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
......@@ -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))
......@@ -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
......@@ -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 属性控制游戏时间流逝的速度。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册