Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
6418086a
宇宙模拟器
项目概览
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看板
提交
6418086a
编写于
4月 06, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
f73aa981
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
44 addition
and
16 deletion
+44
-16
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+44
-16
未找到文件。
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
6418086a
...
@@ -11,7 +11,7 @@ from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, A
...
@@ -11,7 +11,7 @@ from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, A
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
Text
,
Panel
,
color
,
camera
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
def
create_bodies
():
def
create_bodies
():
...
@@ -26,15 +26,15 @@ def create_bodies():
...
@@ -26,15 +26,15 @@ def create_bodies():
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.6e2
)
# 太阳放大 60 倍,距离保持不变
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.6e2
)
# 太阳放大 60 倍,距离保持不变
bodies
=
[
bodies
=
[
sun
,
sun
,
Mercury
(
name
=
"水星"
,
size_scale
=
3e3
),
# 水星放大 3
000 倍,距离保持不变
Mercury
(
name
=
"水星"
,
size_scale
=
2e3
),
# 水星放大 2
000 倍,距离保持不变
Venus
(
name
=
"金星"
,
size_scale
=
4e3
),
# 金星放大 4
000 倍,距离保持不变
Venus
(
name
=
"金星"
,
size_scale
=
2e3
),
# 金星放大 2
000 倍,距离保持不变
Earth
(
name
=
"地球"
,
size_scale
=
4e3
),
# 地球放大 4
000 倍,距离保持不变
Earth
(
name
=
"地球"
,
size_scale
=
2e3
),
# 地球放大 2
000 倍,距离保持不变
Mars
(
name
=
"火星"
,
size_scale
=
4e3
),
# 火星放大 4
000 倍,距离保持不变
Mars
(
name
=
"火星"
,
size_scale
=
2e3
),
# 火星放大 2
000 倍,距离保持不变
Asteroids
(
name
=
"小行星群"
,
size_scale
=
3.2e2
,
#
Asteroids(name="小行星群", size_scale=3.2e2,
parent
=
sun
),
# 小行星群模拟(仅 ursina 模拟器支持)
#
parent=sun), # 小行星群模拟(仅 ursina 模拟器支持)
Jupiter
(
name
=
"木星"
,
size_scale
=
0.
7
e3
),
# 木星放大 600 倍,距离保持不变
Jupiter
(
name
=
"木星"
,
size_scale
=
0.
6
e3
),
# 木星放大 600 倍,距离保持不变
Saturn
(
name
=
"土星"
,
size_scale
=
0.
7
e3
),
# 土星放大 600 倍,距离保持不变
Saturn
(
name
=
"土星"
,
size_scale
=
0.
6
e3
),
# 土星放大 600 倍,距离保持不变
Uranus
(
name
=
"天王星"
,
size_scale
=
0.7e3
),
# 天王星放大
6
00 倍,距离保持不变
Uranus
(
name
=
"天王星"
,
size_scale
=
0.7e3
),
# 天王星放大
7
00 倍,距离保持不变
Neptune
(
name
=
"海王星"
,
size_scale
=
1e3
),
# 海王星放大 1000 倍,距离保持不变
Neptune
(
name
=
"海王星"
,
size_scale
=
1e3
),
# 海王星放大 1000 倍,距离保持不变
Pluto
(
name
=
"冥王星"
,
size_scale
=
10e3
),
# 冥王星放大 10000 倍,距离保持不变(从太阳系的行星中排除)
Pluto
(
name
=
"冥王星"
,
size_scale
=
10e3
),
# 冥王星放大 10000 倍,距离保持不变(从太阳系的行星中排除)
]
]
...
@@ -46,13 +46,14 @@ def create_bodies():
...
@@ -46,13 +46,14 @@ def create_bodies():
return
bodies
return
bodies
def
create_light
():
def
create_light
(
size_scale
=
1e4
):
"""
"""
用天体模拟一个光子
用天体模拟一个光子
@return:
@return:
"""
"""
return
Body
(
name
=
'光速'
,
mass
=
0
,
size_scale
=
1e4
,
color
=
(
255
,
255
,
0
),
return
Body
(
name
=
'光速'
,
mass
=
0
,
size_scale
=
size_scale
,
color
=
(
255
,
255
,
0
),
init_position
=
[
AU
/
2
,
0
,
0
],
# init_position=[AU / 3, 0, 0],
init_position
=
[
AU
/
12
,
0
,
0
],
init_velocity
=
[
0
,
0
,
299792.458
]).
set_light_disable
(
True
)
# 1光速=299792.458 千米/秒(km/秒)
init_velocity
=
[
0
,
0
,
299792.458
]).
set_light_disable
(
True
)
# 1光速=299792.458 千米/秒(km/秒)
...
@@ -87,6 +88,10 @@ arrived_bodies = []
...
@@ -87,6 +88,10 @@ arrived_bodies = []
text_panel
=
None
text_panel
=
None
arrived_info
=
""
arrived_info
=
""
CAMERA_FOLLOW_LIGHT
=
None
# 不跟随光
CAMERA_FOLLOW_LIGHT
=
'ForwardView'
# 向前看
# CAMERA_FOLLOW_LIGHT = 'SideView' # 侧面看
def
on_reset
():
def
on_reset
():
global
arrived_info
global
arrived_info
...
@@ -100,6 +105,14 @@ def on_ready():
...
@@ -100,6 +105,14 @@ def on_ready():
global
text_panel
global
text_panel
text_panel
=
create_text_panel
()
text_panel
=
create_text_panel
()
if
CAMERA_FOLLOW_LIGHT
==
"SideView"
:
camera
.
parent
=
light_body
.
planet
camera
.
rotation_y
=
-
85
elif
CAMERA_FOLLOW_LIGHT
==
"ForwardView"
:
camera
.
parent
=
light_body
.
planet
light_body
.
planet
.
enabled
=
False
camera
.
rotation_y
=
-
15
def
on_timer_changed
(
time_text
,
time_data
):
def
on_timer_changed
(
time_text
,
time_data
):
global
arrived_info
global
arrived_info
...
@@ -125,16 +138,31 @@ UrsinaEvent.on_reset_subscription(on_reset)
...
@@ -125,16 +138,31 @@ UrsinaEvent.on_reset_subscription(on_reset)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
if
CAMERA_FOLLOW_LIGHT
==
"SideView"
:
position
=
(
2
*
AU
,
0
,
-
AU
/
8
)
show_trail
=
True
light_size_scale
=
1e3
elif
CAMERA_FOLLOW_LIGHT
==
"ForwardView"
:
position
=
(
0
,
AU
/
10
,
-
AU
)
show_trail
=
False
light_size_scale
=
1e2
else
:
position
=
(
0
,
2
*
AU
,
-
11
*
AU
)
show_trail
=
True
light_size_scale
=
5e3
# 创建太阳系天体(忽略质量,引力无效,初速度全部为0)
# 创建太阳系天体(忽略质量,引力无效,初速度全部为0)
bodies
=
create_bodies
()
bodies
=
create_bodies
()
# 创建一个以光速前进的天体(模拟一个光子,质量为0才能达到光速)
# 创建一个以光速前进的天体(模拟一个光子,质量为0才能达到光速)
light_body
=
create_light
()
light_body
=
create_light
(
size_scale
=
light_size_scale
)
bodies
.
append
(
light_body
)
bodies
.
append
(
light_body
)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
60
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
ursina_run
(
bodies
,
60
,
show_trail
=
True
,
show_timer
=
True
,
position
=
position
,
show_trail
=
show_trail
,
show_timer
=
True
,
# view_closely=True,
bg_music
=
"sounds/interstellar.mp3"
)
bg_music
=
"sounds/interstellar.mp3"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录