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

太阳系三体模拟器

上级 bfb30361
...@@ -16,12 +16,12 @@ from simulators.ursina.ursina_config import UrsinaConfig ...@@ -16,12 +16,12 @@ from simulators.ursina.ursina_config import UrsinaConfig
class UiSlider(Slider): class UiSlider(Slider):
def __init__(self, text, min=0.01, max=3, default=1): def __init__(self, text, min=0.01, max=3, step=.01, default=1):
# Text.default_font = 'msyhl.ttc' # 'simsun.ttc' # Text.default_font = 'msyhl.ttc' # 'simsun.ttc'
super().__init__(text=text, super().__init__(text=text,
height=Text.size, height=Text.size,
y=-.6, y=-.6,
step=.01, step=step,
min=min, min=min,
max=max, max=max,
default=default, default=default,
...@@ -35,10 +35,9 @@ class UiSlider(Slider): ...@@ -35,10 +35,9 @@ class UiSlider(Slider):
# self.height *= 8/10 # self.height *= 8/10
class SwithButton(ButtonGroup): class SwithButton(ButtonGroup):
def __init__(self, options, default, tooltips=None): def __init__(self, options, default, tooltips=None):
super().__init__(options, min_selection=1,default=default, super().__init__(options, min_selection=1, default=default,
selected_color=color.rgba(0.1, 0.6, 0.1, 1.0), ignore_paused=True, selected_color=color.rgba(0.1, 0.6, 0.1, 1.0), ignore_paused=True,
color=color.rgba(0.0, 0.0, 0.0, 0.5)) color=color.rgba(0.0, 0.0, 0.0, 0.5))
# self.label.scale = 0.8 # self.label.scale = 0.8
......
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
class UrsinaConfig: class UrsinaConfig:
# 常量定义 # 常量定义
# 天体缩放的因子(不能太大,否则无法容得下大数量级的天体) # 天体缩放的因子(不能太大,否则无法容得下大数量级的天体)调整 5e-7 最佳
SCALE_FACTOR = 5e-10 SCALE_FACTOR = 5e-7
# 旋转因子为1,则为正常的转速 # 旋转因子为1,则为正常的转速
ROTATION_SPEED_FACTOR = 1.0 ROTATION_SPEED_FACTOR = 1.0
# ROTATION_SPEED_FACTOR = 0.01 # ROTATION_SPEED_FACTOR = 0.01
# 中文字体(微软雅黑) # 中文字体(微软雅黑)
CN_FONT = "msyhl.ttc" # 'simsun.ttc' 仿宋体 CN_FONT = "msyhl.ttc" # 'simsun.ttc' 仿宋体
CN_FONT = 'simsun.ttc' # 仿宋体 # CN_FONT = 'simsun.ttc' # 仿宋体
# 速度的倍数 # 速度的倍数
__run_speed_factor = 1.0 __run_speed_factor = 1.0
...@@ -37,6 +37,8 @@ class UrsinaConfig: ...@@ -37,6 +37,8 @@ class UrsinaConfig:
trail_length = 200 trail_length = 200
# 默认秒数(0表示默认) # 默认秒数(0表示默认)
seconds_per = 0 seconds_per = 0
# # 控制摄像机动作速度(天体越大,速度越快,天体越小,速度越慢)
# control_camera_speed = 1
__body_size_factor = 1.0 __body_size_factor = 1.0
......
...@@ -27,12 +27,12 @@ class UrsinaUI: ...@@ -27,12 +27,12 @@ class UrsinaUI:
self.no_trail_button_text = "○ " self.no_trail_button_text = "○ "
self.trail_button_text = "○--" self.trail_button_text = "○--"
application.time_scale = 0.5 # application.time_scale = 0.5
self.slider_body_spin_factor = UiSlider(text='自转速度', min=0.01, max=30, default=1) self.slider_body_spin_factor = UiSlider(text='自转速度', min=0.01, max=30, default=1)
self.slider_body_size_factor = UiSlider(text='天体缩放', min=0.1, max=100, default=1) self.slider_body_size_factor = UiSlider(text='天体缩放', min=0.1, max=100, default=1)
self.slider_run_speed_factor = UiSlider(text="运行速度", min=0.01, max=80, default=1) self.slider_run_speed_factor = UiSlider(text="运行速度", min=0.01, max=80, default=1)
self.slider_control_speed_factor = UiSlider(text="控制速度", min=0.01, max=30, default=application.time_scale) self.slider_control_speed_factor = UiSlider(text="控制速度", min=0.01, max=50, default=application.time_scale)
self.slider_trail_length = UiSlider(text="拖尾长度", min=30, max=500, default=UrsinaConfig.trail_length) self.slider_trail_length = UiSlider(text="拖尾长度", min=30, max=500, step=10, default=UrsinaConfig.trail_length)
self.slider_body_size_factor.on_value_changed = self.on_slider_body_size_changed self.slider_body_size_factor.on_value_changed = self.on_slider_body_size_changed
self.slider_body_spin_factor.on_value_changed = self.on_slider_body_spin_changed self.slider_body_spin_factor.on_value_changed = self.on_slider_body_spin_changed
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# ============================================================================== # ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \ from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \
load_texture, held_keys load_texture, held_keys, distance
from ursina.prefabs.first_person_controller import FirstPersonController from ursina.prefabs.first_person_controller import FirstPersonController
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
...@@ -57,9 +57,25 @@ class UrsinaSimulator(Simulator): ...@@ -57,9 +57,25 @@ class UrsinaSimulator(Simulator):
self.ursina_views.append(view) self.ursina_views.append(view)
# planets.append(newPlanet) # planets.append(newPlanet)
# x += cp[i] * 10 # x += cp[i] * 10
self.adj_application_time_scale()
UrsinaEvent.on_searching_bodies_subscription(type(self).__name__, self.on_searching_bodies) UrsinaEvent.on_searching_bodies_subscription(type(self).__name__, self.on_searching_bodies)
def adj_application_time_scale(self):
max_distance = 0
for b1 in self.body_views:
for b2 in self.body_views:
if b1 is b2:
continue
d = distance(b1.planet, b2.planet)
if d > max_distance:
max_distance = d
# UrsinaConfig.control_camera_speed = round(max_distance * 10, 2)
time_scale = round(pow(max_distance, 1 / 3), 2)
if time_scale < 0.01:
time_scale = 0.01
application.time_scale = time_scale
def on_searching_bodies(self, **kwargs): def on_searching_bodies(self, **kwargs):
views = [] views = []
for view in self.body_views: for view in self.body_views:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册