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

Python超人-宇宙模拟器

上级 a8205024
......@@ -29,4 +29,4 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_DAY, position=(-300000, 200000, -1300000), show_trail=True)
ursina_run(bodies, SECONDS_PER_MONTH, position=(-300000, 200000, -1300000), show_trail=True)
......@@ -65,6 +65,7 @@ class Planet(Entity):
rotation = (0, 0, 0)
UrsinaEvent.on_reset_subscription(self.on_reset)
UrsinaEvent.on_body_size_changed_subscription(self.change_body_scale)
super().__init__(
# model="sphere",
......@@ -100,16 +101,18 @@ class Planet(Entity):
# 创建行星环(目前只有土星环)
create_rings(self)
def update(self):
def change_body_scale(self):
if hasattr(self.body, "torus_stars"):
# 星环小天体群(主要模拟小行星群,非一个天体)不受 body_size_factor 影响
self.scale = self.init_scale
else:
self.scale = self.init_scale * UrsinaConfig.body_size_factor
def update(self):
self.change_body_scale()
pos = self.body_view.position * UrsinaConfig.SCALE_FACTOR
if self.body.parent is None:
# TODO: ????????
# self.x = -pos[1]
# self.y = pos[2]
# self.z = pos[0]
......@@ -180,7 +183,6 @@ class Planet(Entity):
self.f_parent = b
break
pos = self.f_parent.position * UrsinaConfig.SCALE_FACTOR
# TODO: ????????
# self.x = -pos[1]
# self.y = pos[2]
# self.z = pos[0]
......
......@@ -205,6 +205,7 @@ class ControlHandler(EventHandler):
def on_slider_body_size_changed(self):
UrsinaConfig.body_size_factor = self.ui.slider_body_size_factor.value
UrsinaEvent.on_body_size_changed()
def on_slider_run_speed_changed(self):
UrsinaConfig.run_speed_factor = self.ui.slider_run_speed_factor.value
......
......@@ -33,6 +33,7 @@ class UiSlider(Slider):
dynamic=True)
# self.label.scale *= 8/10
self.label.font = UrsinaConfig.CN_FONT
self.knob.ignore_paused = True
# self.knob.text_entity.font = ""
# self.knob.text_entity.scale *= 8/10
# self.height *= 8/10
......
......@@ -24,6 +24,17 @@ class UrsinaEvent:
UrsinaEvent.on_searching_bodies_funcs = []
# 应用运行的订阅事件
UrsinaEvent.on_application_run_callback = []
#
UrsinaEvent.on_body_size_changed_callback = []
@staticmethod
def on_body_size_changed_subscription(fun):
UrsinaEvent.on_body_size_changed_callback.append(fun)
@staticmethod
def on_body_size_changed():
for f in UrsinaEvent.on_body_size_changed_callback:
f()
@staticmethod
def on_application_run_callback_subscription(fun):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册