Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
11ec7b03
宇宙模拟器
项目概览
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看板
提交
11ec7b03
编写于
4月 06, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
6418086a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
92 addition
and
81 deletion
+92
-81
sim_scenes/func.py
sim_scenes/func.py
+72
-0
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+20
-81
未找到文件。
sim_scenes/func.py
浏览文件 @
11ec7b03
...
...
@@ -154,6 +154,78 @@ def create_fig_ax(styles={}):
return
fig
,
ax
def
create_solar_system_bodies
(
ignore_mass
=
False
,
init_velocity
=
None
):
"""
创建太阳系天体(忽略质量,引力无效,初速度全部为0)
太阳、小行星环、
八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
冥王星
以下展示的效果为太阳系真实的距离
@return:
"""
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.6e2
)
# 太阳放大 60 倍,距离保持不变
bodies
=
[
sun
,
Mercury
(
name
=
"水星"
,
size_scale
=
2e3
),
# 水星放大 2000 倍,距离保持不变
Venus
(
name
=
"金星"
,
size_scale
=
2e3
),
# 金星放大 2000 倍,距离保持不变
Earth
(
name
=
"地球"
,
size_scale
=
2e3
),
# 地球放大 2000 倍,距离保持不变
Mars
(
name
=
"火星"
,
size_scale
=
2e3
),
# 火星放大 2000 倍,距离保持不变
# Asteroids(name="小行星群", size_scale=3.2e2,
# parent=sun), # 小行星群模拟(仅 ursina 模拟器支持)
Jupiter
(
name
=
"木星"
,
size_scale
=
0.6e3
),
# 木星放大 600 倍,距离保持不变
Saturn
(
name
=
"土星"
,
size_scale
=
0.6e3
),
# 土星放大 600 倍,距离保持不变
Uranus
(
name
=
"天王星"
,
size_scale
=
0.7e3
),
# 天王星放大 700 倍,距离保持不变
Neptune
(
name
=
"海王星"
,
size_scale
=
1e3
),
# 海王星放大 1000 倍,距离保持不变
Pluto
(
name
=
"冥王星"
,
size_scale
=
10e3
),
# 冥王星放大 10000 倍,距离保持不变(从太阳系的行星中排除)
]
# 遍历所有天体,
for
idx
,
body
in
enumerate
(
bodies
):
body
.
set_ignore_mass
(
ignore_mass
)
# 忽略质量(引力无效)
if
init_velocity
is
not
None
:
body
.
init_velocity
=
init_velocity
return
bodies
def
create_light
(
size_scale
,
init_position
):
"""
用天体模拟一个光子
@return:
"""
from
bodies
import
Body
return
Body
(
name
=
'光速'
,
mass
=
0
,
size_scale
=
size_scale
,
color
=
(
255
,
255
,
0
),
init_position
=
init_position
,
init_velocity
=
[
0
,
0
,
299792.458
]).
set_light_disable
(
True
)
# 1光速=299792.458 千米/秒(km/秒)
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
# 创建一个 Panel 组件
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
panel
=
Panel
(
parent
=
None
,
model
=
'quad'
,
# texture='white_cube',
color
=
color
.
gray
,
origin
=
(
-
.
48
,
.
48
),
scale
=
(
width
,
height
),
position
=
(
-
.
88
,
0.3
,
0
),
alpha
=
0.2
)
# 创建一个 Text 组件用于显示消息
text
=
Text
(
parent
=
panel
,
text
=
''
,
origin
=
(
-
.
5
,
.
5
),
scale
=
(
height
*
5
,
width
*
5
),
font
=
UrsinaConfig
.
CN_FONT
,
# background=True,
# background_color=color.clear
)
return
text
if
__name__
==
'__main__'
:
from
bodies
import
Sun
,
Earth
...
...
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
11ec7b03
...
...
@@ -8,112 +8,52 @@
# ==============================================================================
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
,
Moon
,
Asteroids
,
Body
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_YEAR
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
create_solar_system_bodies
,
create_text_panel
,
create_light
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
Text
,
Panel
,
color
,
camera
,
Vec3
def
create_bodies
():
"""
创建太阳系天体(忽略质量,引力无效,初速度全部为0)
太阳、小行星环、
八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
冥王星
以下展示的效果为太阳系真实的距离
@return:
"""
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.6e2
)
# 太阳放大 60 倍,距离保持不变
bodies
=
[
sun
,
Mercury
(
name
=
"水星"
,
size_scale
=
2e3
),
# 水星放大 2000 倍,距离保持不变
Venus
(
name
=
"金星"
,
size_scale
=
2e3
),
# 金星放大 2000 倍,距离保持不变
Earth
(
name
=
"地球"
,
size_scale
=
2e3
),
# 地球放大 2000 倍,距离保持不变
Mars
(
name
=
"火星"
,
size_scale
=
2e3
),
# 火星放大 2000 倍,距离保持不变
# Asteroids(name="小行星群", size_scale=3.2e2,
# parent=sun), # 小行星群模拟(仅 ursina 模拟器支持)
Jupiter
(
name
=
"木星"
,
size_scale
=
0.6e3
),
# 木星放大 600 倍,距离保持不变
Saturn
(
name
=
"土星"
,
size_scale
=
0.6e3
),
# 土星放大 600 倍,距离保持不变
Uranus
(
name
=
"天王星"
,
size_scale
=
0.7e3
),
# 天王星放大 700 倍,距离保持不变
Neptune
(
name
=
"海王星"
,
size_scale
=
1e3
),
# 海王星放大 1000 倍,距离保持不变
Pluto
(
name
=
"冥王星"
,
size_scale
=
10e3
),
# 冥王星放大 10000 倍,距离保持不变(从太阳系的行星中排除)
]
# 遍历所有天体,
for
idx
,
body
in
enumerate
(
bodies
):
body
.
set_ignore_mass
(
True
)
# 忽略质量(引力无效)
body
.
init_velocity
=
[
0
,
0
,
0
]
# 初速度为0
return
bodies
def
create_light
(
size_scale
=
1e4
):
"""
用天体模拟一个光子
@return:
"""
return
Body
(
name
=
'光速'
,
mass
=
0
,
size_scale
=
size_scale
,
color
=
(
255
,
255
,
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/秒)
def
create_text_panel
(
width
=
0.35
,
height
=
.
5
):
# 创建一个 Panel 组件
panel
=
Panel
(
parent
=
None
,
model
=
'quad'
,
# texture='white_cube',
color
=
color
.
gray
,
origin
=
(
-
.
48
,
.
48
),
scale
=
(
width
,
height
),
position
=
(
-
.
88
,
0.3
,
0
),
alpha
=
0.2
)
# 创建一个 Text 组件用于显示消息
text
=
Text
(
parent
=
panel
,
text
=
''
,
origin
=
(
-
.
5
,
.
5
),
scale
=
(
height
*
5
,
width
*
5
),
font
=
UrsinaConfig
.
CN_FONT
,
# background=True,
# background_color=color.clear
)
return
text
# 已到达天体列表
arrived_bodies
=
[]
text_panel
=
None
arrived_info
=
""
CAMERA_FOLLOW_LIGHT
=
None
# 不跟随光
CAMERA_FOLLOW_LIGHT
=
'ForwardView'
# 向前看
#
CAMERA_FOLLOW_LIGHT = 'ForwardView' # 向前看
# CAMERA_FOLLOW_LIGHT = 'SideView' # 侧面看
def
on_reset
():
global
arrived_info
arrived_bodies
.
clear
()
arrived_info
=
""
arrived_info
=
"
[00:00:00] 从 [太阳] 出发
\n\n
"
if
text_panel
is
not
None
:
text_panel
.
text
=
""
text_panel
.
text
=
arrived_info
on_reset
()
# 订阅重新开始事件
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
def
on_ready
():
global
text_panel
text_panel
=
create_text_panel
()
text_panel
.
text
=
arrived_info
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
.
parent
=
light_body
.
planet
camera
.
rotation_y
=
-
15
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
def
on_timer_changed
(
time_text
,
time_data
):
global
arrived_info
years
,
days
,
hours
,
minutes
,
seconds
=
time_data
...
...
@@ -133,28 +73,27 @@ def on_timer_changed(time_text, time_data):
# 订阅计时器事件(记录已到达天体列表)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 订阅重新开始事件
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
if
CAMERA_FOLLOW_LIGHT
==
"SideView"
:
position
=
(
2
*
AU
,
0
,
-
AU
/
8
)
show_trail
=
True
light_size_scale
=
1e3
light_init_position
=
[
AU
/
3
,
0
,
0
]
elif
CAMERA_FOLLOW_LIGHT
==
"ForwardView"
:
position
=
(
0
,
AU
/
10
,
-
AU
)
show_trail
=
False
light_size_scale
=
1e2
light_init_position
=
[
AU
/
12
,
0
,
0
]
else
:
position
=
(
0
,
2
*
AU
,
-
11
*
AU
)
show_trail
=
True
light_size_scale
=
5e3
light_init_position
=
[
AU
/
3
,
0
,
0
]
# 创建太阳系天体(忽略质量,引力无效,初速度全部为0)
bodies
=
create_
bodies
(
)
bodies
=
create_
solar_system_bodies
(
ignore_mass
=
True
,
init_velocity
=
[
0
,
0
,
0
]
)
# 创建一个以光速前进的天体(模拟一个光子,质量为0才能达到光速)
light_body
=
create_light
(
size_scale
=
light_size_scale
)
light_body
=
create_light
(
light_size_scale
,
light_init_position
)
bodies
.
append
(
light_body
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录