Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
91d92d69
宇宙模拟器
项目概览
Python_超人
/
宇宙模拟器
通知
19
Star
2
Fork
0
代码
文件
提交
分支
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看板
提交
91d92d69
编写于
3月 26, 2024
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
488311d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
10 deletion
+61
-10
bodies/body.py
bodies/body.py
+1
-1
sim_scenes/featured/tri_bodies_01.py
sim_scenes/featured/tri_bodies_01.py
+59
-8
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+1
-1
未找到文件。
bodies/body.py
浏览文件 @
91d92d69
...
...
@@ -453,7 +453,7 @@ class Body(metaclass=ABCMeta):
"""
self
.
position
=
copy
.
deepcopy
(
self
.
init_position
)
self
.
velocity
=
copy
.
deepcopy
(
self
.
init_velocity
)
self
.
clear_his_position
()
# def kinetic_energy(self):
# """
# 计算动能(千焦耳)
...
...
sim_scenes/featured/tri_bodies_01.py
浏览文件 @
91d92d69
...
...
@@ -10,7 +10,12 @@ from bodies import Sun, Earth
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_YEAR
,
SECONDS_PER_MONTH
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
create_sphere_sky
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
application
,
window
,
camera
,
EditorCamera
import
numpy
as
np
from
simulators.ursina_simulator
import
UrsinaSimulator
if
__name__
==
'__main__'
:
"""
...
...
@@ -27,32 +32,78 @@ if __name__ == '__main__':
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
250
,
195
,
47
)),
# 红色太阳
Sun
(
mass
=
2.5e30
,
init_position
=
[
0
,
-
8.5e8
,
-
2000000
],
init_velocity
=
[
12.0
,
0
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
198
,
29
,
3
)),
# 黄色太阳
Earth
(
init_position
=
[
0
,
-
3.5e8
,
3000000
],
init_velocity
=
[
13.360
,
0
,
0
],
Earth
(
init_position
=
[
0
,
-
3.5e8
,
3000000
],
init_velocity
=
[
13.360
,
0
,
0
],
rotate_angle
=
0
,
size_scale
=
4e3
,
distance_scale
=
1
),
# 地球放大 4000 倍,距离保持不变
]
# 使用 mayavi 查看的运行效果
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=0)
def
on_ready
():
from
ursina
import
application
,
window
from
ursina
import
camera
sky
=
create_sphere_sky
(
scale
=
80000
,
texture
=
"bg_pan_blue.jpg"
)
window
.
borderless
=
False
sky
=
create_sphere_sky
(
scale
=
80000
,
texture
=
"bg_pan_deep_blue.jpg"
)
camera
.
clip_plane_near
=
1
camera
.
clip_plane_far
=
sky
.
scale_x
*
1.5
camera
.
clip_plane_far
=
sky
.
scale_x
*
1.5
def
on_timer_changed
(
time_data
:
TimeData
):
pass
total_days
=
time_data
.
total_days
ec
=
UrsinaSimulator
.
EditorCamera
print
(
total_days
)
if
100
<
total_days
<
3000
:
camera
.
position
+=
camera
.
right
*
0.1
camera
.
position
+=
camera
.
down
*
0.01
elif
3200
<
total_days
<
3600
:
ec
.
target_z
-=
7.5
elif
6000
<
total_days
<
7500
:
camera
.
position
+=
camera
.
right
*
1
camera
.
position
+=
camera
.
down
*
0.5
elif
10800
<
total_days
<
12000
:
camera
.
position
+=
camera
.
right
*
1
# elif total_days > 10765:
elif
total_days
>
17000
:
UrsinaEvent
.
on_reset
()
# camera.position = UrsinaConfig.SCALE_FACTOR * np.array([10 * AU, -2 * AU, -20 * AU]),
# elif total_days > 3500:
# camera.position += camera.back * 0.1
def
on_reset
():
reset_camera
()
def
reset_camera
():
# 参考 EditorCamera 中的 elif key == 'scroll up':
ec
=
UrsinaSimulator
.
EditorCamera
if
not
hasattr
(
ec
,
"original_target_z"
):
ec
.
original_target_z
=
ec
.
target_z
camera
.
original_position
=
camera
.
position
else
:
ec
.
target_z
=
ec
.
original_target_z
camera
.
position
=
camera
.
original_position
UrsinaConfig
.
trail_type
=
"line"
# UrsinaConfig.trail_length = 91
# UrsinaConfig.trail_type = "curve_line"
UrsinaConfig
.
trail_length
=
50
# UrsinaConfig.trail_length = 1000
UrsinaConfig
.
trail_thickness_factor
=
2
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_YEAR
/
3
,
cosmic_bg
=
''
,
show_grid
=
False
,
position
=
(
20
*
AU
,
0
,
-
40
*
AU
),
# position=(20 * AU, 0, -40 * AU),
position
=
(
10
*
AU
,
-
2
*
AU
,
-
20
*
AU
),
show_camera_info
=
False
,
show_control_info
=
False
,
show_trail
=
True
,
timer_enabled
=
True
)
\ No newline at end of file
timer_enabled
=
True
)
simulators/ursina_simulator.py
浏览文件 @
91d92d69
...
...
@@ -404,7 +404,7 @@ class UrsinaSimulator(Simulator):
audio
=
Audio
(
bg_music
,
pitch
=
1
,
loop
=
True
,
autoplay
=
True
)
audio
.
volume
=
0.3
EditorCamera
(
ignore_paused
=
True
)
UrsinaSimulator
.
EditorCamera
=
EditorCamera
(
ignore_paused
=
True
)
if
self
.
show_timer
or
self
.
timer_enabled
:
UrsinaEvent
.
on_reset
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录