Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
09817f55
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1075
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看板
提交
09817f55
编写于
3月 16, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
太阳系三体模拟器
上级
e9e2c9d3
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
46 addition
and
20 deletion
+46
-20
bodies/asteroids.py
bodies/asteroids.py
+5
-2
bodies/body.py
bodies/body.py
+2
-1
scenes/solar_system_2.py
scenes/solar_system_2.py
+3
-2
simulators/simulator.py
simulators/simulator.py
+3
-3
simulators/views/body_view.py
simulators/views/body_view.py
+2
-1
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+31
-11
未找到文件。
bodies/asteroids.py
浏览文件 @
09817f55
...
@@ -29,7 +29,9 @@ class Asteroids(Body):
...
@@ -29,7 +29,9 @@ class Asteroids(Body):
def
__init__
(
self
,
name
=
"Asteroids"
,
mass
=
1.9891e30
,
def
__init__
(
self
,
name
=
"Asteroids"
,
mass
=
1.9891e30
,
init_position
=
[
0
,
0
,
0
],
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
"asteroids.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
0.6130
):
texture
=
"asteroids.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
0.6130
,
parent
=
None
):
params
=
{
params
=
{
"name"
:
name
,
"name"
:
name
,
"mass"
:
mass
,
"mass"
:
mass
,
...
@@ -40,7 +42,8 @@ class Asteroids(Body):
...
@@ -40,7 +42,8 @@ class Asteroids(Body):
"texture"
:
texture
,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
"size_scale"
:
size_scale
,
"distance_scale"
:
distance_scale
,
"distance_scale"
:
distance_scale
,
"rotation_speed"
:
rotation_speed
"rotation_speed"
:
rotation_speed
,
"parent"
:
parent
}
}
super
().
__init__
(
**
params
)
super
().
__init__
(
**
params
)
# 环状星群
# 环状星群
...
...
bodies/body.py
浏览文件 @
09817f55
...
@@ -21,7 +21,7 @@ class Body(metaclass=ABCMeta):
...
@@ -21,7 +21,7 @@ class Body(metaclass=ABCMeta):
def
__init__
(
self
,
name
,
mass
,
init_position
,
init_velocity
,
def
__init__
(
self
,
name
,
mass
,
init_position
,
init_velocity
,
density
=
5e3
,
color
=
(
125
/
255
,
125
/
255
,
125
/
255
),
density
=
5e3
,
color
=
(
125
/
255
,
125
/
255
,
125
/
255
),
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
None
):
rotation_speed
=
None
,
parent
=
None
):
"""
"""
天体类
天体类
:param name: 天体名称
:param name: 天体名称
...
@@ -70,6 +70,7 @@ class Body(metaclass=ABCMeta):
...
@@ -70,6 +70,7 @@ class Body(metaclass=ABCMeta):
# 是否显示
# 是否显示
self
.
appeared
=
True
self
.
appeared
=
True
self
.
parent
=
parent
@
property
@
property
def
has_rings
(
self
):
def
has_rings
(
self
):
...
...
scenes/solar_system_2.py
浏览文件 @
09817f55
...
@@ -22,12 +22,13 @@ if __name__ == '__main__':
...
@@ -22,12 +22,13 @@ if __name__ == '__main__':
# 2、为了达到最佳的显示效果,对每个行星天体的距离进行了缩放
# 2、为了达到最佳的显示效果,对每个行星天体的距离进行了缩放
# region 构建太阳系
# region 构建太阳系
sun
=
Sun
(
size_scale
=
0.8e2
)
bodies
=
[
bodies
=
[
Sun
(
size_scale
=
0.8e2
),
# 太阳放大 80 倍
sun
,
# 太阳放大 80 倍
Mercury
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 水星放大 4000 倍,距离放大 1.3 倍
Mercury
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 水星放大 4000 倍,距离放大 1.3 倍
Venus
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 金星放大 4000 倍,距离放大 1.3 倍
Venus
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 金星放大 4000 倍,距离放大 1.3 倍
Earth
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 地球放大 4000 倍,距离放大 1.3 倍
Earth
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 地球放大 4000 倍,距离放大 1.3 倍
Asteroids
(
size_scale
=
3e2
),
# 小行星模拟
Asteroids
(
size_scale
=
3e2
,
parent
=
sun
),
# 小行星模拟
Mars
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 火星放大 4000 倍,距离放大 1.3 倍
Mars
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 火星放大 4000 倍,距离放大 1.3 倍
Jupiter
(
size_scale
=
0.68e3
,
distance_scale
=
0.65
),
# 木星放大 680 倍,距离缩小到真实距离的 0.65
Jupiter
(
size_scale
=
0.68e3
,
distance_scale
=
0.65
),
# 木星放大 680 倍,距离缩小到真实距离的 0.65
Saturn
(
size_scale
=
0.68e3
,
distance_scale
=
0.52
),
# 土星放大 680 倍,距离缩小到真实距离的 0.52
Saturn
(
size_scale
=
0.68e3
,
distance_scale
=
0.52
),
# 土星放大 680 倍,距离缩小到真实距离的 0.52
...
...
simulators/simulator.py
浏览文件 @
09817f55
...
@@ -32,7 +32,7 @@ class Simulator(metaclass=ABCMeta):
...
@@ -32,7 +32,7 @@ class Simulator(metaclass=ABCMeta):
:return:
:return:
"""
"""
for
body
in
self
.
bodies_sys
.
bodies
:
for
body
in
self
.
bodies_sys
.
bodies
:
view
=
viewer_type
(
body
)
view
=
viewer_type
(
body
,
self
.
bodies_sys
)
self
.
body_views
.
append
(
view
)
self
.
body_views
.
append
(
view
)
def
evolve
(
self
,
dt
:
int
):
def
evolve
(
self
,
dt
:
int
):
...
@@ -64,8 +64,8 @@ class Simulator(metaclass=ABCMeta):
...
@@ -64,8 +64,8 @@ class Simulator(metaclass=ABCMeta):
view
.
update
()
view
.
update
()
self
.
bodies_sys
.
bodies
=
list
(
filter
(
lambda
b
:
b
.
appeared
,
self
.
bodies_sys
.
bodies
))
self
.
bodies_sys
.
bodies
=
list
(
filter
(
lambda
b
:
b
.
appeared
,
self
.
bodies_sys
.
bodies
))
self
.
body_views
=
list
(
filter
(
lambda
b
:
b
.
appeared
,
self
.
body_views
))
self
.
body_views
=
list
(
filter
(
lambda
b
:
b
.
appeared
,
self
.
body_views
))
@
abstractmethod
@
abstractmethod
def
run
(
self
,
dt
:
int
,
**
kwargs
):
def
run
(
self
,
dt
:
int
,
**
kwargs
):
...
...
simulators/views/body_view.py
浏览文件 @
09817f55
...
@@ -18,8 +18,9 @@ class BodyView(metaclass=ABCMeta):
...
@@ -18,8 +18,9 @@ class BodyView(metaclass=ABCMeta):
天体视图(天体效果展示用)
天体视图(天体效果展示用)
"""
"""
def
__init__
(
self
,
body
:
Body
):
def
__init__
(
self
,
body
:
Body
,
bodies_system
):
self
.
body
=
body
self
.
body
=
body
self
.
bodies_system
=
bodies_system
self
.
sphere
=
None
self
.
sphere
=
None
if
self
.
body
.
texture
is
None
or
self
.
body
.
texture
==
''
:
if
self
.
body
.
texture
is
None
or
self
.
body
.
texture
==
''
:
self
.
color
=
tuple
(
np
.
array
(
body
.
color
)
/
255
)
self
.
color
=
tuple
(
np
.
array
(
body
.
color
)
/
255
)
...
...
simulators/views/ursina_view.py
浏览文件 @
09817f55
...
@@ -153,7 +153,7 @@ class Planet(Entity):
...
@@ -153,7 +153,7 @@ class Planet(Entity):
try
:
try
:
pos
=
self
.
position
pos
=
self
.
position
except
Exception
as
e
:
except
Exception
as
e
:
self
.
destroy_
me
()
self
.
destroy_
all
()
return
return
trails_keys
=
self
.
trails
.
keys
()
trails_keys
=
self
.
trails
.
keys
()
# 如果有拖尾
# 如果有拖尾
...
@@ -193,10 +193,12 @@ class Planet(Entity):
...
@@ -193,10 +193,12 @@ class Planet(Entity):
def
turn
(
self
):
def
turn
(
self
):
pos
=
self
.
body_view
.
position
*
UrsinaConfig
.
SCALE_FACTOR
pos
=
self
.
body_view
.
position
*
UrsinaConfig
.
SCALE_FACTOR
if
self
.
body_view
.
body
.
parent
is
None
:
self
.
x
=
-
pos
[
1
]
self
.
x
=
-
pos
[
1
]
self
.
y
=
pos
[
2
]
self
.
y
=
pos
[
2
]
self
.
z
=
pos
[
0
]
self
.
z
=
pos
[
0
]
else
:
self
.
follow_parent
()
dt
=
0
dt
=
0
if
hasattr
(
self
.
body_view
.
body
,
"dt"
):
if
hasattr
(
self
.
body_view
.
body
,
"dt"
):
...
@@ -217,7 +219,7 @@ class Planet(Entity):
...
@@ -217,7 +219,7 @@ class Planet(Entity):
# 天体旋转
# 天体旋转
self
.
rotation_y
-=
self
.
rotspeed
self
.
rotation_y
-=
self
.
rotspeed
except
Exception
as
e
:
except
Exception
as
e
:
self
.
destroy_
me
()
self
.
destroy_
all
()
return
return
# 如果有行星环
# 如果有行星环
...
@@ -231,6 +233,18 @@ class Planet(Entity):
...
@@ -231,6 +233,18 @@ class Planet(Entity):
if
len
(
self
.
body_view
.
body
.
his_position
())
>
1
:
if
len
(
self
.
body_view
.
body
.
his_position
())
>
1
:
self
.
create_trails
()
self
.
create_trails
()
def
follow_parent
(
self
):
if
not
hasattr
(
self
.
body_view
,
"bodies_system"
):
return
sys
=
self
.
body_view
.
bodies_system
for
b
in
sys
.
bodies
:
if
self
.
body_view
.
body
.
parent
==
b
:
pos
=
b
.
position
*
UrsinaConfig
.
SCALE_FACTOR
self
.
x
=
-
pos
[
1
]
self
.
y
=
pos
[
2
]
self
.
z
=
pos
[
0
]
def
create_rings
(
self
):
def
create_rings
(
self
):
"""
"""
创建行星环(使用土星贴图)
创建行星环(使用土星贴图)
...
@@ -252,11 +266,17 @@ class Planet(Entity):
...
@@ -252,11 +266,17 @@ class Planet(Entity):
# 设置行星环不受灯光影响,否则看不清行星环
# 设置行星环不受灯光影响,否则看不清行星环
self
.
ring
.
set_light_off
()
self
.
ring
.
set_light_off
()
def
destroy_me
(
self
):
def
destroy_all
(
self
):
# 从天体系统中移除自己(TODO:暂时还不能移除)
# self.body_view.bodies_system.bodies.remove(self.body_view.body)
# 删除拖尾
for
entity
,
pos
in
self
.
trails
.
items
():
for
entity
,
pos
in
self
.
trails
.
items
():
destroy
(
entity
)
destroy
(
entity
)
# 如果有行星环,则删除行星环
if
hasattr
(
self
,
"ring"
):
if
hasattr
(
self
,
"ring"
):
destroy
(
self
.
ring
)
destroy
(
self
.
ring
)
# 最后删除自己
destroy
(
self
)
destroy
(
self
)
...
@@ -265,8 +285,8 @@ class UrsinaView(BodyView):
...
@@ -265,8 +285,8 @@ class UrsinaView(BodyView):
ursina天体视图(天体效果展示用)
ursina天体视图(天体效果展示用)
"""
"""
def
__init__
(
self
,
body
:
Body
):
def
__init__
(
self
,
body
:
Body
,
bodies_system
):
BodyView
.
__init__
(
self
,
body
)
BodyView
.
__init__
(
self
,
body
,
bodies_system
)
self
.
velocity
=
body
.
velocity
self
.
velocity
=
body
.
velocity
self
.
planet
=
Planet
(
self
)
self
.
planet
=
Planet
(
self
)
...
@@ -281,9 +301,9 @@ class UrsinaView(BodyView):
...
@@ -281,9 +301,9 @@ class UrsinaView(BodyView):
"""
"""
self
.
planet
.
turn
()
self
.
planet
.
turn
()
def
appear
(
self
):
def
appear
(
self
):
pass
pass
def
disappear
(
self
):
def
disappear
(
self
):
self
.
planet
.
destroy_me
()
self
.
planet
.
destroy_all
()
self
.
appeared
=
False
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录