Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
7076f48a
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1074
Star
131
Fork
128
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
太阳系三体模拟器
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7076f48a
编写于
3月 16, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
太阳系三体模拟器
上级
7904d98f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
25 deletion
+49
-25
common/system.py
common/system.py
+5
-5
simulators/ursina/ursina_config.py
simulators/ursina/ursina_config.py
+4
-0
simulators/ursina/ursina_ui.py
simulators/ursina/ursina_ui.py
+24
-0
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+16
-20
未找到文件。
common/system.py
浏览文件 @
7076f48a
...
...
@@ -80,11 +80,11 @@ class System(object):
"""
if
not
body
.
appeared
:
# 不显示
return
False
if
self
.
max_distance
>
0
:
# 超过了 max_distance 距离,则不显示,并消失
if
calculate_distance
(
body
.
position
)
>
self
.
max_distance
:
body
.
appeared
=
False
return
False
#
if self.max_distance > 0:
#
# 超过了 max_distance 距离,则不显示,并消失
#
if calculate_distance(body.position) > self.max_distance:
#
body.appeared = False
#
return False
return
True
...
...
simulators/ursina/ursina_config.py
浏览文件 @
7076f48a
...
...
@@ -28,6 +28,10 @@ class UrsinaConfig:
__on_reset_funcs
=
[]
show_trail
=
False
# 拖尾球体的数量
trail_length
=
200
@
property
@
classmethod
def
run_speed_factor
(
cls
):
...
...
simulators/ursina/ursina_ui.py
浏览文件 @
7076f48a
...
...
@@ -39,10 +39,23 @@ class UrsinaUI:
self
.
slider_body_spin_factor
.
on_value_changed
=
self
.
on_slider_body_spin_changed
self
.
slider_run_speed_factor
.
on_value_changed
=
self
.
on_slider_run_speed_changed
self
.
slider_control_speed_factor
.
on_value_changed
=
self
.
on_slider_control_speed_changed
self
.
slider_trail_length
=
Slider
(
text
=
"拖尾长度"
,
y
=-
.
1
,
step
=
1
,
min
=
30
,
max
=
500
,
default
=
UrsinaConfig
.
trail_length
,
color
=
color
.
rgba
(
0.0
,
0.0
,
0.0
,
0.5
))
self
.
slider_trail_length
.
on_value_changed
=
self
.
on_slider_trail_length_changed
self
.
on_off_switch
=
ButtonGroup
((
'||'
,
'○'
),
min_selection
=
1
,
y
=
0
,
default
=
'○'
,
selected_color
=
color
.
green
,
ignore_paused
=
True
,
color
=
color
.
rgba
(
0.0
,
0.0
,
0.0
,
0.5
))
self
.
on_off_switch
.
selected_color
=
color
.
red
self
.
on_off_trail
=
ButtonGroup
((
' '
,
'...'
),
min_selection
=
1
,
y
=
0
,
default
=
' '
,
selected_color
=
color
.
green
,
ignore_paused
=
True
,
color
=
color
.
rgba
(
0.0
,
0.0
,
0.0
,
0.5
))
self
.
on_off_trail
.
on_value_changed
=
self
.
on_off_trail_changed
self
.
point_button
=
Button
(
text
=
'寻找'
,
origin
=
(
0
,
0
),
y
=
2
,
on_click
=
self
.
on_point_button_click
,
color
=
color
.
rgba
(
0.0
,
0.0
,
0.0
,
0.5
))
self
.
reset_button
=
Button
(
text
=
'重置'
,
origin
=
(
0
,
0
),
y
=
2
,
...
...
@@ -57,6 +70,8 @@ class UrsinaUI:
self
.
point_button
,
self
.
reset_button
,
self
.
on_off_switch
,
self
.
on_off_trail
,
self
.
slider_trail_length
,
self
.
slider_body_spin_factor
,
self
.
slider_run_speed_factor
,
self
.
slider_control_speed_factor
...
...
@@ -67,6 +82,12 @@ class UrsinaUI:
wp
.
x
=
-
wp
.
scale_x
self
.
wp
=
wp
def
on_off_trail_changed
(
self
):
if
self
.
on_off_trail
.
value
==
"..."
:
UrsinaConfig
.
show_trail
=
True
else
:
UrsinaConfig
.
show_trail
=
False
def
on_point_button_click
(
self
):
pass
...
...
@@ -81,6 +102,9 @@ class UrsinaUI:
self
.
on_off_switch
.
selected_color
=
color
.
red
application
.
paused
=
False
def
on_slider_trail_length_changed
(
self
):
UrsinaConfig
.
trail_length
=
int
(
self
.
slider_trail_length
.
value
)
def
on_slider_control_speed_changed
(
self
):
application
.
time_scale
=
self
.
slider_control_speed_factor
.
value
...
...
simulators/views/ursina_view.py
浏览文件 @
7076f48a
...
...
@@ -76,19 +76,9 @@ class Planet(Entity):
def
on_reset
(
self
):
# 删除拖尾
for
entity
,
pos
in
self
.
trails
.
items
():
destroy
(
entity
)
self
.
clear_trails
()
self
.
body_view
.
body
.
reset
()
# pos = body.init_position * body.distance_scale * UrsinaConfig.SCALE_FACTOR
# vel = body.init_velocity
# self.x = -pos[1]
# self.y = pos[2]
# self.z = pos[0]
# self.x = pos[0]
# self.y = pos[1]
# self.z = pos[2]
def
__init__
(
self
,
body_view
:
BodyView
):
self
.
body_view
=
body_view
self
.
rotation_speed
=
self
.
body_view
.
body
.
rotation_speed
...
...
@@ -139,8 +129,6 @@ class Planet(Entity):
"""
# 存放拖尾球体
self
.
trails
=
{}
# 拖尾球体的数量
self
.
trail_len
=
100
# 根据天体的颜色获取拖尾的颜色
trail_color
=
conv_to_vec4_color
(
self
.
body_view
.
body
.
color
)
...
...
@@ -190,7 +178,7 @@ class Planet(Entity):
self
.
trails
[
self
.
create_trail
(
pos
)]
=
pos
# 计算拖尾球体超过的数量
trail_overflow_count
=
len
(
self
.
trails
)
-
self
.
trail_len
trail_overflow_count
=
len
(
self
.
trails
)
-
UrsinaConfig
.
trail_length
if
trail_overflow_count
>
0
:
# 如果拖尾球体超过的数量,就删除之前的拖尾球体
...
...
@@ -248,9 +236,12 @@ class Planet(Entity):
self
.
rotation_y
,
self
.
rotation_z
)
# 有时候第一个位置不正确,所以判断一下有历史记录后在创建
if
len
(
self
.
body_view
.
body
.
his_position
())
>
1
:
self
.
create_trails
()
if
UrsinaConfig
.
show_trail
:
# 有时候第一个位置不正确,所以判断一下有历史记录后在创建
if
len
(
self
.
body_view
.
body
.
his_position
())
>
1
:
self
.
create_trails
()
else
:
self
.
clear_trails
()
def
follow_parent
(
self
):
if
not
hasattr
(
self
.
body_view
,
"bodies_system"
):
...
...
@@ -284,13 +275,18 @@ class Planet(Entity):
# 设置行星环不受灯光影响,否则看不清行星环
self
.
ring
.
set_light_off
()
def
clear_trails
(
self
):
if
not
hasattr
(
self
,
"trails"
):
return
# 删除拖尾
for
entity
,
pos
in
self
.
trails
.
items
():
destroy
(
entity
)
def
destroy_all
(
self
):
# 从天体系统中移除自己(TODO:暂时还不能移除)
# self.body_view.bodies_system.bodies.remove(self.body_view.body)
# 删除拖尾
for
entity
,
pos
in
self
.
trails
.
items
():
destroy
(
entity
)
self
.
clear_trails
()
# 如果有行星环,则删除行星环
if
hasattr
(
self
,
"ring"
):
destroy
(
self
.
ring
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录