Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
a8205024
宇宙模拟器
项目概览
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看板
提交
a8205024
编写于
4月 02, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
c9128166
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
212 addition
and
20 deletion
+212
-20
bodies/body.py
bodies/body.py
+17
-1
data/gravity_slingshot_2.json
data/gravity_slingshot_2.json
+108
-0
sim_scenes/fiction/fixed_stars_1.py
sim_scenes/fiction/fixed_stars_1.py
+0
-0
sim_scenes/fiction/fixed_stars_2.py
sim_scenes/fiction/fixed_stars_2.py
+62
-0
sim_scenes/func.py
sim_scenes/func.py
+1
-1
sim_scenes/interest/images/eye.png
sim_scenes/interest/images/eye.png
+0
-0
sim_scenes/science/gravity_slingshot_2.py
sim_scenes/science/gravity_slingshot_2.py
+12
-10
sim_scenes/solar_system/earth_at_night.py
sim_scenes/solar_system/earth_at_night.py
+3
-3
sim_scenes/ursina_json_sim.py
sim_scenes/ursina_json_sim.py
+3
-1
simulators/ursina/entities/entity_utils.py
simulators/ursina/entities/entity_utils.py
+6
-4
未找到文件。
bodies/body.py
浏览文件 @
a8205024
...
@@ -90,6 +90,8 @@ class Body(metaclass=ABCMeta):
...
@@ -90,6 +90,8 @@ class Body(metaclass=ABCMeta):
self
.
resolution
=
None
self
.
resolution
=
None
self
.
light_disable
=
False
self
.
light_disable
=
False
self
.
__has_rings
=
False
def
set_light_disable
(
self
,
value
):
def
set_light_disable
(
self
,
value
):
"""
"""
设置灯光为无效
设置灯光为无效
...
@@ -150,7 +152,11 @@ class Body(metaclass=ABCMeta):
...
@@ -150,7 +152,11 @@ class Body(metaclass=ABCMeta):
是否为带光环的天体(土星为 True)
是否为带光环的天体(土星为 True)
:return:
:return:
"""
"""
return
False
return
self
.
__has_rings
@
has_rings
.
setter
def
has_rings
(
self
,
value
):
self
.
__has_rings
=
value
@
property
@
property
def
is_fixed_star
(
self
):
def
is_fixed_star
(
self
):
...
@@ -402,7 +408,17 @@ class Body(metaclass=ABCMeta):
...
@@ -402,7 +408,17 @@ class Body(metaclass=ABCMeta):
body_data
.
pop
(
"is_fixed_star"
)
body_data
.
pop
(
"is_fixed_star"
)
body
=
FixedStar
(
**
body_data
)
body
=
FixedStar
(
**
body_data
)
else
:
else
:
has_rings
=
False
if
"has_rings"
in
body_data
:
if
body_data
[
"has_rings"
]:
has_rings
=
True
body_data
.
pop
(
"has_rings"
)
body
=
Body
(
**
body_data
)
body
=
Body
(
**
body_data
)
if
has_rings
:
body
.
has_rings
=
True
# [x, y, z]->[-y, z, x]
# [x, y, z]->[-y, z, x]
# body.init_velocity = [-body.init_velocity[1],body.init_velocity[2],body.init_velocity[0]]
# body.init_velocity = [-body.init_velocity[1],body.init_velocity[2],body.init_velocity[0]]
# body.init_position = [-body.init_position[1],body.init_position[2],body.init_position[0]]
# body.init_position = [-body.init_position[1],body.init_position[2],body.init_position[0]]
...
...
data/gravity_slingshot_2.json
0 → 100644
浏览文件 @
a8205024
{
"bodies"
:
[
{
"name"
:
"木星"
,
"mass"
:
1.8982e+27
,
"init_position"
:
[
-37399468.0
,
0.0
,
0.0
],
"init_velocity"
:
[
0.0
,
0.0
,
0.0
],
"density"
:
1326.0
,
"color"
:
[
173
,
121
,
92
],
"texture"
:
"jupiter1.jpg"
,
"size_scale"
:
100.0
,
"distance_scale"
:
1.0
,
"rotation_speed"
:
36.2537
,
"ignore_mass"
:
false
,
"is_fixed_star"
:
false
,
"trail_color"
:
[
173
,
121
,
92
]
},
{
"name"
:
"土星"
,
"mass"
:
5.6834e+26
,
"init_position"
:
[
-183577232.0
,
0.0
,
99731912.0
],
"init_velocity"
:
[
0.0
,
0.0
,
0.0
],
"density"
:
687.0
,
"color"
:
[
219
,
189
,
159
],
"has_rings"
:
true
,
"texture"
:
"saturn.jpg"
,
"size_scale"
:
100.0
,
"distance_scale"
:
1.0
,
"rotation_speed"
:
33.7711
,
"ignore_mass"
:
false
,
"is_fixed_star"
:
false
,
"trail_color"
:
[
219
,
189
,
159
]
},
{
"name"
:
"地球"
,
"mass"
:
5.97237e+24
,
"init_position"
:
[
0.0
,
0.0
,
0.0
],
"init_velocity"
:
[
-38.0
,
0.0
,
-0.20000000298023224
],
"density"
:
5507.85
,
"color"
:
[
7
,
0
,
162
],
"texture"
:
"earth1.jpg"
,
"size_scale"
:
300.0
,
"distance_scale"
:
1.0
,
"rotation_speed"
:
15
,
"ignore_mass"
:
false
,
"is_fixed_star"
:
false
,
"trail_color"
:
[
7
,
0
,
162
]
}
],
"params"
:
{
"dt"
:
604800
,
"position"
:
[
-80000000.0
,
29919574.139999997
,
-224396806.04999998
],
"show_trail"
:
true
,
"show_name"
:
false
}
}
\ No newline at end of file
sim_scenes/fiction/fixed_stars.py
→
sim_scenes/fiction/fixed_stars
_1
.py
浏览文件 @
a8205024
文件已移动
sim_scenes/fiction/fixed_stars_2.py
0 → 100644
浏览文件 @
a8205024
# -*- coding:utf-8 -*-
# title :恒星演示
# description :恒星演示
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Sirius
,
Rigel
,
Bellatrix
,
Alcyone
,
Antares
,
Arcturus
,
Aldebaran
,
Betelgeuse
from
bodies
import
EtaCarinae
,
YCanumVenaticorum
,
VYCanisMajoris
,
UYScuti
,
CarinaeV382
,
Stephenson_2_18
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
,
SECONDS_PER_DAY
from
sim_scenes.func
import
mayavi_run
,
mpl_run
,
ursina_run
from
bodies.body
import
Body
,
AU
if
__name__
==
'__main__'
:
"""
恒星演示
"""
# 构建两个天体对象(太阳、地球)
D
=
5e5
SIZE_SCALE
=
0.5
bodies
=
[
Earth
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
Sun
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 太阳
# Sirius(size_scale=SIZE_SCALE, ignore_mass=True), # 天狼星A 质量倍数 2.02 半径倍数 1.71
Bellatrix
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 参宿五 质量倍数 8.6 半径倍数 5.75
# Alcyone(size_scale=SIZE_SCALE, ignore_mass=True), # 昴宿六 质量倍数 6 半径倍数 9.5
Arcturus
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 大角星 质量倍数 1.1 半径倍数 25.7
# Aldebaran(size_scale=SIZE_SCALE, ignore_mass=True), # 毕宿五 质量倍数 1.16 半径倍数 44.13
Rigel
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 参宿七 质量倍数 18 半径倍数 78
# YCanumVenaticorum(size_scale=SIZE_SCALE, ignore_mass=True), # 猎犬座Y 质量倍数 3.0 半径倍数 215
EtaCarinae
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 海山二 质量倍数 125 半径倍数 278
# Antares(size_scale=SIZE_SCALE, ignore_mass=True), # 心宿二 质量倍数 15 半径倍数 680
CarinaeV382
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
),
# 船底座V382 质量倍数 39 半径倍数 747
# Betelgeuse(size_scale=SIZE_SCALE, ignore_mass=True), # 参宿四 质量倍数 19 半径倍数 1180
# VYCanisMajoris(size_scale=SIZE_SCALE, ignore_mass=True), # 大犬座VY 质量倍数 30 半径倍数 1400
# UYScuti(size_scale=SIZE_SCALE, ignore_mass=True), # 盾牌座 UY 质量倍数 10 半径倍数 1708
Stephenson_2_18
(
size_scale
=
SIZE_SCALE
,
ignore_mass
=
True
)
# 史蒂文森2-18 质量倍数 40.0 半径倍数 2150
]
distance_sum
=
0
for
idx
,
body
in
enumerate
(
bodies
):
body
.
rotation_speed
/=
10
if
body
.
is_fixed_star
:
body
.
light_on
=
False
# 关闭灯光效果,只有太阳对地球有灯光效果
if
idx
==
0
:
d
=
0
else
:
# d = (body.raduis + bodies[idx - 1].raduis) * SIZE_SCALE
d
=
pow
((
body
.
raduis
+
bodies
[
idx
-
1
].
raduis
)
*
SIZE_SCALE
,
1.0
)
*
1.1
# d = body.raduis * SIZE_SCALE
# d = (body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE * 1.1 + D
body
.
init_velocity
=
[
0
,
0
,
0
]
# body.init_position = [-(distance_sum + d), AU, body.raduis * SIZE_SCALE]
# d = (distance_sum + d)
body
.
init_position
=
[
-
body
.
raduis
*
SIZE_SCALE
/
1.1
,
body
.
raduis
*
SIZE_SCALE
/
1.1
,
d
]
distance_sum
+=
d
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_WEEK
,
position
=
(
0
,
100000
,
-
AU
/
500
),
show_name
=
True
,
bg_music
=
"sounds/universe_03.mp3"
)
sim_scenes/func.py
浏览文件 @
a8205024
...
@@ -94,7 +94,7 @@ def ursina_run(bodies,
...
@@ -94,7 +94,7 @@ def ursina_run(bodies,
"show_trail"
:
show_trail
,
"show_name"
:
show_name
})
"show_trail"
:
show_trail
,
"show_name"
:
show_name
})
print
(
f
"
{
save_as_json
}
文件生成成功!"
)
print
(
f
"
{
save_as_json
}
文件生成成功!"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"
{
save_as_json
}
文件生成失败!"
+
str
(
e
))
raise
Exception
(
f
"
{
save_as_json
}
文件生成失败!"
+
str
(
e
))
return
return
simulator
=
UrsinaSimulator
(
body_sys
)
simulator
=
UrsinaSimulator
(
body_sys
)
view_azimuth
=
0
# 暂时未用
view_azimuth
=
0
# 暂时未用
...
...
sim_scenes/interest/images/eye.png
查看替换文件 @
c9128166
浏览文件 @
a8205024
3.1 KB
|
W:
|
H:
3.1 KB
|
W:
|
H:
2-up
Swipe
Onion skin
sim_scenes/science/gravity_slingshot_2.py
浏览文件 @
a8205024
...
@@ -13,17 +13,19 @@ from bodies.body import AU
...
@@ -13,17 +13,19 @@ from bodies.body import AU
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
"""
"""
模拟流浪地球
经
过木星、土星加速
模拟流浪地球
通
过木星、土星加速
"""
"""
# params 为不同参数量的加速效果,j_pos为木星位置;s_pos为土星位置;e_vel为地球初始速度
# 地球初始速度≈36km/s,通过木星加速到 42.43km/s(加速度为0时的速度),再通过土星加速到 108.64km/s(加速度为0时的速度)
params
=
{
"j_pos"
:
[
-
AU
/
4
,
0
,
0
],
"s_pos"
:
[
-
0.9
*
AU
+
7.5e6
,
0
,
AU
/
1.5
],
"e_vel"
:
[
-
36
,
0
,
-
0.2
]}
# 地球初始速度≈38km/s,通过木星加速到 51.96km/s(加速度为0时的速度),再通过土星加速到 71.27km/s(加速度为0时的速度)
params
=
{
"j_pos"
:
[
-
AU
/
4
,
0
,
0
],
"s_pos"
:
[
-
1.3
*
AU
+
1.09e7
,
0
,
AU
/
1.5
],
"e_vel"
:
[
-
38
,
0
,
-
0.2
]}
bodies
=
[
bodies
=
[
Jupiter
(
size_scale
=
1e2
,
init_position
=
[
-
AU
/
4
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 木星放大 100 倍
Jupiter
(
size_scale
=
1e2
,
init_position
=
params
[
"j_pos"
],
init_velocity
=
[
0
,
0
,
0
]),
# 木星放大 100 倍
Saturn
(
size_scale
=
1e2
,
init_position
=
[
-
1.5
*
AU
,
0
,
AU
/
1.5
],
init_velocity
=
[
0
,
0
,
0
]),
# 土星放大 100 倍
Saturn
(
size_scale
=
1e2
,
init_position
=
params
[
"s_pos"
],
init_velocity
=
[
0
,
0
,
0
]),
# 土星放大 100 倍
Earth
(
size_scale
=
3e2
,
# 地球放大 300 倍
Earth
(
size_scale
=
3e2
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
params
[
"e_vel"
]),
# 地球放大 300 倍
init_position
=
[
0
,
0
,
0
],
#
# init_velocity=[0, 33, -1],
init_velocity
=
[
-
10
,
0
,
-
1
],
# 朝向木星的速度为 38km/s,-1 km/s 是为了防止地球正面对着木星冲去
# init_velocity=[0, 50, -1],
),
]
]
# 使用 mayavi 查看的运行效果
# 使用 mayavi 查看的运行效果
...
@@ -32,4 +34,4 @@ if __name__ == '__main__':
...
@@ -32,4 +34,4 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_
MONTH
,
position
=
(
0
,
AU
/
2
,
-
2
*
AU
),
show_trail
=
True
,
view_closely
=
True
)
ursina_run
(
bodies
,
SECONDS_PER_
WEEK
,
position
=
(
-
8e7
,
AU
/
5
,
-
1.5
*
AU
),
show_trail
=
True
,
view_closely
=
True
)
sim_scenes/solar_system/earth_at_night.py
浏览文件 @
a8205024
...
@@ -23,9 +23,9 @@ if __name__ == '__main__':
...
@@ -23,9 +23,9 @@ if __name__ == '__main__':
Earth
(
texture
=
"earth_at_night_hd.jpg"
,
Earth
(
texture
=
"earth_at_night_hd.jpg"
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
100
,
ignore_mass
=
True
).
set_resolution
(
resolution
),
size_scale
=
100
,
ignore_mass
=
True
).
set_resolution
(
resolution
),
Earth
(
texture
=
"earth_hd.jpg"
,
#
Earth(texture="earth_hd.jpg",
init_position
=
[
-
10
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
#
init_position=[-10, 0, 0], init_velocity=[0, 0, 0],
size_scale
=
100
,
ignore_mass
=
True
).
set_resolution
(
resolution
)
#
size_scale=100, ignore_mass=True).set_resolution(resolution)
]
]
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
...
...
sim_scenes/ursina_json_sim.py
浏览文件 @
a8205024
...
@@ -29,7 +29,9 @@ if __name__ == '__main__':
...
@@ -29,7 +29,9 @@ if __name__ == '__main__':
# TODO: 去掉注释,完美数据的三体模型的演示05(画大花)
# TODO: 去掉注释,完美数据的三体模型的演示05(画大花)
# bodies, params = Body.build_bodies_from_json('../data/tri_bodies_perfect_05.json')
# bodies, params = Body.build_bodies_from_json('../data/tri_bodies_perfect_05.json')
# TODO: 去掉注释,引力弹弓的演示
# TODO: 去掉注释,引力弹弓的演示
bodies
,
params
=
Body
.
build_bodies_from_json
(
'../data/gravity_slingshot.json'
)
# bodies, params = Body.build_bodies_from_json('../data/gravity_slingshot.json')
# TODO: 去掉注释,引力弹弓的演示2(通过木星、土星加速)
bodies
,
params
=
Body
.
build_bodies_from_json
(
'../data/gravity_slingshot_2.json'
)
dt
=
params
[
"dt"
]
if
"dt"
in
params
else
SECONDS_PER_YEAR
dt
=
params
[
"dt"
]
if
"dt"
in
params
else
SECONDS_PER_YEAR
position
=
params
[
"position"
]
if
"position"
in
params
else
(
0
,
0
,
0
)
position
=
params
[
"position"
]
if
"position"
in
params
else
(
0
,
0
,
0
)
...
...
simulators/ursina/entities/entity_utils.py
浏览文件 @
a8205024
...
@@ -27,14 +27,16 @@ def create_name_text(parent):
...
@@ -27,14 +27,16 @@ def create_name_text(parent):
@return:
@return:
"""
"""
b_color
=
parent
.
body_view
.
color
b_color
=
parent
.
body_view
.
color
parent
.
name_text
=
Text
(
parent
.
body_view
.
body
.
name
,
scale
=
1
,
billboard
=
True
,
parent
=
parent
,
name_text
=
Text
(
parent
.
body_view
.
body
.
name
,
scale
=
1
,
billboard
=
True
,
parent
=
parent
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
,
origin
=
(
0
,
0
))
origin
=
(
0
,
0
))
parent
.
name_text
.
background
.
color
=
color
.
rgba
(
b_color
[
0
],
b_color
[
1
],
b_color
[
2
],
0.3
)
name_text
.
background
.
color
=
color
.
rgba
(
b_color
[
0
],
b_color
[
1
],
b_color
[
2
],
0.3
)
name_text
.
resolution
=
24
# self.name_text.scale = self.scale
# self.name_text.scale = self.scale
inverse_color
=
get_inverse_color
(
b_color
)
inverse_color
=
get_inverse_color
(
b_color
)
parent
.
name_text
.
color
=
color
.
rgba
(
inverse_color
[
0
],
inverse_color
[
1
],
inverse_color
[
2
],
1
)
name_text
.
color
=
color
.
rgba
(
inverse_color
[
0
],
inverse_color
[
1
],
inverse_color
[
2
],
1
)
return
parent
.
name_text
parent
.
name_text
=
name_text
return
name_text
def
trail_init
(
parent
):
def
trail_init
(
parent
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录