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

Python超人-宇宙模拟器

上级 e7f55fee
......@@ -115,6 +115,7 @@ def ursina_run(bodies,
show_trail=False,
show_name=False,
show_timer=False,
timer_enabled=False,
save_as_json=None,
view_closely=False):
"""
......@@ -128,6 +129,7 @@ def ursina_run(bodies,
@param show_trail: 是否显示拖尾
@param show_name: 是否显示天体名称
@param show_timer: 是否显示计时器
@param timer_enabled: 计时器是否有效
@param save_as_json: 将所有天体的信息保存为 json 文件
@param view_closely: 是否近距离查看天体
@return:
......@@ -170,6 +172,7 @@ def ursina_run(bodies,
cosmic_bg=cosmic_bg,
show_grid=show_grid,
show_timer=show_timer,
timer_enabled=timer_enabled,
bg_music=bg_music,
view_closely=view_closely)
......@@ -222,7 +225,7 @@ def create_solar_system_bodies(ignore_mass=False, init_velocity=None):
Mercury(name="水星", size_scale=0.3e3), # 水星放大 300 倍,距离保持不变
Venus(name="金星", size_scale=0.3e3), # 金星放大 300 倍,距离保持不变
Earth(name="地球", size_scale=0.3e3), # 地球放大 300 倍,距离保持不变
Moon(name="月球", init_position=[0, 0, 363104 + AU],
Moon(name="月球", init_position=[0, 0, 363104 + AU],
size_scale=0.3e3), # 月球放大 300 倍,距离保持不变
Mars(name="火星", size_scale=0.3e3), # 火星放大 300 倍,距离保持不变
# Asteroids(name="小行星群", size_scale=3.2e2,
......
......@@ -56,5 +56,5 @@ if __name__ == '__main__':
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 10 * AU, -10 * AU),
show_timer=True,
timer_enabled=True,
bg_music="sounds/interstellar.mp3")
......@@ -16,12 +16,14 @@ from simulators.ursina.ursina_event import UrsinaEvent
class Timer(Text):
def __init__(self):
def __init__(self, show=True):
# 创建一个文本对象来显示计时器的时间
super().__init__(text=' ', position=(0.70, -0.465),
origin=(-0.5, 0.5),
font=UrsinaConfig.CN_FONT, background=True)
UrsinaEvent.on_timer_changed_subscription(self.on_timer_changed)
if not show:
self.enabled = False
def on_timer_changed(self, time_data: TimeData):
self.text = time_data.time_text
......
......@@ -209,14 +209,14 @@ class UrsinaSimulator(Simulator):
evolve_dt = evolve_dt * self.interval_fator
super().evolve(evolve_dt)
if self.show_timer:
if self.show_timer or self.timer_enabled:
timer = BodyTimer()
timer.calc_time(evolve_dt)
def create_timer(self):
def create_timer(self, show=True):
from simulators.ursina.entities.timer import Timer
# 创建一个文本对象来显示计时器的时间
self.timer = Timer()
self.timer = Timer(show)
return self.timer
def cosmic_background(self, texture='../textures/cosmic2.jpg'):
......@@ -262,6 +262,10 @@ class UrsinaSimulator(Simulator):
if "show_timer" in kwargs:
self.show_timer = kwargs["show_timer"]
self.timer_enabled = False
if "timer_enabled" in kwargs:
self.timer_enabled = kwargs["timer_enabled"]
if view_closely:
# 近距离查看
if isinstance(view_closely, float):
......@@ -314,9 +318,13 @@ class UrsinaSimulator(Simulator):
if cosmic_bg is not None and os.path.exists(cosmic_bg):
self.cosmic_background(cosmic_bg)
if self.show_timer:
self.create_timer()
self.timer_enabled = True
# 创建和显示计时器
self.create_timer(True)
elif self.timer_enabled:
# 创建计时器,但是不显示
self.create_timer(False)
# 防止打开中文输入法
# self.switch_to_english_input_method()
......@@ -346,7 +354,7 @@ class UrsinaSimulator(Simulator):
EditorCamera(ignore_paused=True)
if self.show_timer:
if self.show_timer or self.timer_enabled:
UrsinaEvent.on_reset()
UrsinaEvent.on_ready()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册