Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
efbdb7d1
宇宙模拟器
项目概览
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看板
提交
efbdb7d1
编写于
11月 12, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
9d2b1121
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
74 deletion
+72
-74
sim_scenes/tri_bodies/one_way_foil.py
sim_scenes/tri_bodies/one_way_foil.py
+72
-74
未找到文件。
sim_scenes/tri_bodies/one_way_foil.py
浏览文件 @
efbdb7d1
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
# title :
三体
一向箔场景模拟
# title :一向箔场景模拟
# description :
三体
一向箔场景模拟
# description :一向箔场景模拟
# author :Python超人
# author :Python超人
# date :2023-10-27
# date :2023-10-27
# link :https://gitcode.net/pythoncr/
# link :https://gitcode.net/pythoncr/
...
@@ -23,7 +23,7 @@ from simulators.func import ext_fun_for_method
...
@@ -23,7 +23,7 @@ from simulators.func import ext_fun_for_method
class
OneWayFoilSim
:
class
OneWayFoilSim
:
"""
"""
三体
一向箔场景模拟
一向箔场景模拟
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -50,37 +50,37 @@ class OneWayFoilSim:
...
@@ -50,37 +50,37 @@ class OneWayFoilSim:
]
]
# endregion
# endregion
self
.
two
_way_foil_dt_factor
=
1
self
.
one
_way_foil_dt_factor
=
1
self
.
sun
.
two_way_foil_dt
=
0.003
*
self
.
two
_way_foil_dt_factor
self
.
sun
.
one_way_foil_dt
=
0.003
*
self
.
one
_way_foil_dt_factor
self
.
saturn
.
two_way_foil_dt
=
0.005
*
self
.
two
_way_foil_dt_factor
self
.
saturn
.
one_way_foil_dt
=
0.005
*
self
.
one
_way_foil_dt_factor
self
.
uranus
.
two_way_foil_dt
=
0.002
*
self
.
two
_way_foil_dt_factor
self
.
uranus
.
one_way_foil_dt
=
0.002
*
self
.
one
_way_foil_dt_factor
init_bodies_pos_vels
(
self
.
bodies
)
init_bodies_pos_vels
(
self
.
bodies
)
def
build_
two
_way_foil
(
self
):
def
build_
one
_way_foil
(
self
):
"""
"""
创建一向箔(一个原始的方形一向箔,一个不断扩展的圆形一向箔)
创建一向箔(一个原始的方形一向箔,一个不断扩展的圆形一向箔)
@return:
@return:
"""
"""
# 原始的方形一向箔
# 原始的方形一向箔
self
.
two
_way_foil
=
QuadObj
(
texture
=
'two_way_foil.png'
,
self
.
one
_way_foil
=
QuadObj
(
texture
=
'two_way_foil.png'
,
# size_scale=4e7,
# size_scale=4e7,
size_scale
=
1e7
,
size_scale
=
1e7
,
init_velocity
=
[
0
,
-
50
,
60
],
init_velocity
=
[
0
,
-
50
,
60
],
init_position
=
[
0
,
5
*
AU
,
-
6
*
AU
])
\
init_position
=
[
0
,
5
*
AU
,
-
6
*
AU
])
\
.
set_light_disable
(
True
).
set_ignore_gravity
(
True
)
.
set_light_disable
(
True
).
set_ignore_gravity
(
True
)
# 不断扩展的
圆形
一向箔
# 不断扩展的一向箔
self
.
two_way_foil_circl
e
=
CircleObj
(
texture
=
"two_way_foil_circle.png"
,
self
.
one_way_foil_lin
e
=
CircleObj
(
texture
=
"two_way_foil_circle.png"
,
size_scale
=
self
.
two
_way_foil
.
size_scale
*
2
,
size_scale
=
self
.
one
_way_foil
.
size_scale
*
2
,
)
\
)
\
.
set_light_disable
(
True
).
set_ignore_gravity
(
True
)
.
set_light_disable
(
True
).
set_ignore_gravity
(
True
)
self
.
bodies
.
append
(
self
.
two
_way_foil
)
self
.
bodies
.
append
(
self
.
one
_way_foil
)
self
.
bodies
.
append
(
self
.
two_way_foil_circl
e
)
self
.
bodies
.
append
(
self
.
one_way_foil_lin
e
)
def
build
(
self
):
def
build
(
self
):
self
.
build_solar_system
()
self
.
build_solar_system
()
self
.
build_
two
_way_foil
()
self
.
build_
one
_way_foil
()
def
on_ready
(
self
):
def
on_ready
(
self
):
"""
"""
...
@@ -93,29 +93,27 @@ class OneWayFoilSim:
...
@@ -93,29 +93,27 @@ class OneWayFoilSim:
create_sphere_sky
(
scale
=
200000
)
create_sphere_sky
(
scale
=
200000
)
application
.
time_scale
=
5
application
.
time_scale
=
5
# 圆形一向箔初始化(一开始不显示)
# 圆形一向箔初始化(一开始不显示)
self
.
two_way_foil_circl
e
.
planet
.
rotation_x
=
90
self
.
one_way_foil_lin
e
.
planet
.
rotation_x
=
90
self
.
two_way_foil_circl
e
.
planet
.
enabled
=
False
self
.
one_way_foil_lin
e
.
planet
.
enabled
=
False
def
change_two_way_foil
():
def
change_one_way_foil
():
# 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。
self
.
one_way_foil
.
planet
.
scale_x
=
8.5
# 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条
self
.
one_way_foil
.
planet
.
scale_y
=
0.1
self
.
two_way_foil
.
planet
.
scale_x
=
8.5
self
.
two_way_foil
.
planet
.
scale_y
=
0.1
ext_fun_for_method
(
self
.
two_way_foil
.
planet
,
after_run_fun
=
change_two
_way_foil
)
ext_fun_for_method
(
self
.
one_way_foil
.
planet
,
after_run_fun
=
change_one
_way_foil
)
def
change_
two_way_foil_circl
e
():
def
change_
one_way_foil_lin
e
():
if
hasattr
(
self
.
two_way_foil_circl
e
.
planet
,
"start_scale"
):
if
hasattr
(
self
.
one_way_foil_lin
e
.
planet
,
"start_scale"
):
# 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。
# 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。
# 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条
# 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条
self
.
two_way_foil_circl
e
.
planet
.
start_scale
+=
0.3
self
.
one_way_foil_lin
e
.
planet
.
start_scale
+=
0.3
self
.
two_way_foil_circle
.
planet
.
scale_x
=
self
.
two_way_foil_circl
e
.
planet
.
start_scale
self
.
one_way_foil_line
.
planet
.
scale_x
=
self
.
one_way_foil_lin
e
.
planet
.
start_scale
self
.
two_way_foil_circle
.
planet
.
scale_y
=
1
self
.
one_way_foil_line
.
planet
.
scale_y
=
3
self
.
two_way_foil_circle
.
planet
.
scale_z
=
1
self
.
one_way_foil_line
.
planet
.
scale_z
=
3
# 'box'/'sphere'/'capsule'/'mesh'
# 'box'/'sphere'/'capsule'/'mesh'
self
.
two_way_foil_circl
e
.
planet
.
collider
=
"sphere"
self
.
one_way_foil_lin
e
.
planet
.
collider
=
"sphere"
ext_fun_for_method
(
self
.
two_way_foil_circle
.
planet
,
after_run_fun
=
change_two_way_foil_circl
e
)
ext_fun_for_method
(
self
.
one_way_foil_line
.
planet
,
after_run_fun
=
change_one_way_foil_lin
e
)
def
gen_pixcel_image
(
self
,
planet
):
def
gen_pixcel_image
(
self
,
planet
):
"""
"""
...
@@ -142,7 +140,7 @@ class OneWayFoilSim:
...
@@ -142,7 +140,7 @@ class OneWayFoilSim:
def
flatten_animation
(
self
,
body
):
def
flatten_animation
(
self
,
body
):
"""
"""
天体
二
维化的动画
天体
一维
维化的动画
@param body: 天体
@param body: 天体
@return:
@return:
"""
"""
...
@@ -155,11 +153,11 @@ class OneWayFoilSim:
...
@@ -155,11 +153,11 @@ class OneWayFoilSim:
# 对Y轴进行压平动画,如果压平大小不足 1/50,则继续压缩,直到压缩到 1/50 就不压缩了
# 对Y轴进行压平动画,如果压平大小不足 1/50,则继续压缩,直到压缩到 1/50 就不压缩了
# (如果觉得 1/50 的厚度压的不够,还可以继续压缩,基本上就够了)
# (如果觉得 1/50 的厚度压的不够,还可以继续压缩,基本上就够了)
# if planet.scale_y_v > planet.init_scale_y / 50:
# if planet.scale_y_v > planet.init_scale_y / 50:
if
planet
.
scale_y_v
>
0.5
:
if
planet
.
scale_y_v
>
1
:
planet
.
scale_y_v
/=
1.01
planet
.
scale_y_v
/=
1.01
else
:
else
:
self
.
gen_pixcel_image
(
planet
)
self
.
gen_pixcel_image
(
planet
)
planet
.
scale_x_v
+=
0.
05
planet
.
scale_x_v
+=
0.
1
# 灯光关闭,不然压到2纬就会是黑色
# 灯光关闭,不然压到2纬就会是黑色
planet
.
set_light_off
(
True
)
planet
.
set_light_off
(
True
)
...
@@ -169,9 +167,9 @@ class OneWayFoilSim:
...
@@ -169,9 +167,9 @@ class OneWayFoilSim:
return
warp
return
warp
body
.
is_
2
d
=
True
body
.
is_
1
d
=
True
# 压平时,转速将为以前的 1/
20
0
# 压平时,转速将为以前的 1/
15
0
body
.
planet
.
rotation_speed
/=
20
0
body
.
planet
.
rotation_speed
/=
15
0
# 记录原始的厚度大小
# 记录原始的厚度大小
body
.
planet
.
scale_y_v
=
body
.
planet
.
scale_y
body
.
planet
.
scale_y_v
=
body
.
planet
.
scale_y
body
.
planet
.
init_scale_y
=
body
.
planet
.
scale_y
body
.
planet
.
init_scale_y
=
body
.
planet
.
scale_y
...
@@ -185,7 +183,7 @@ class OneWayFoilSim:
...
@@ -185,7 +183,7 @@ class OneWayFoilSim:
def
get_target
(
self
):
def
get_target
(
self
):
for
body
in
self
.
bodies
:
for
body
in
self
.
bodies
:
if
hasattr
(
body
,
"is_
2
d"
):
if
hasattr
(
body
,
"is_
1
d"
):
continue
continue
return
body
return
body
return
None
return
None
...
@@ -197,12 +195,12 @@ class OneWayFoilSim:
...
@@ -197,12 +195,12 @@ class OneWayFoilSim:
"""
"""
# 如果一向箔和太阳碰撞
# 如果一向箔和太阳碰撞
if
two_bodies_colliding
(
self
.
two
_way_foil
,
self
.
sun
):
if
two_bodies_colliding
(
self
.
one
_way_foil
,
self
.
sun
):
# 隐藏原始一向箔,保持在原地,不在飞行
# 隐藏原始一向箔,保持在原地,不在飞行
# self.
two
_way_foil.planet.enabled = False
# self.
one
_way_foil.planet.enabled = False
self
.
two
_way_foil
.
init_velocity
=
[
0
,
0
,
0
]
self
.
one
_way_foil
.
init_velocity
=
[
0
,
0
,
0
]
def
two
_way_foil_update
():
def
one
_way_foil_update
():
target
=
self
.
get_target
()
target
=
self
.
get_target
()
if
target
is
self
.
sun
:
if
target
is
self
.
sun
:
...
@@ -210,26 +208,26 @@ class OneWayFoilSim:
...
@@ -210,26 +208,26 @@ class OneWayFoilSim:
self
.
sun
.
hide_children
()
self
.
sun
.
hide_children
()
# 让实体A朝向实体B
# 让实体A朝向实体B
# self.
two
_way_foil.planet.look_at(target)
# self.
one
_way_foil.planet.look_at(target)
if
target
is
not
None
:
if
target
is
not
None
:
# 让实体A向着实体B移动
# 让实体A向着实体B移动
dt
=
target
.
two_way_foil_dt
if
hasattr
(
target
,
"two
_way_foil_dt"
)
\
dt
=
target
.
one_way_foil_dt
if
hasattr
(
target
,
"one
_way_foil_dt"
)
\
else
0.003
*
self
.
two
_way_foil_dt_factor
else
0.003
*
self
.
one
_way_foil_dt_factor
# current_time = time.time()
# current_time = time.time()
# if current_time - self.
two
_way_foil.last_time >= 0.1:
# if current_time - self.
one
_way_foil.last_time >= 0.1:
# dt = dt * 2
# dt = dt * 2
# self.
two
_way_foil.last_time = current_time
# self.
one
_way_foil.last_time = current_time
# target.
two
_way_foil_dt = dt
# target.
one
_way_foil_dt = dt
self
.
two
_way_foil
.
planet
.
position
=
\
self
.
one
_way_foil
.
planet
.
position
=
\
lerp
(
self
.
two
_way_foil
.
planet
.
position
,
target
.
planet
.
position
,
dt
)
lerp
(
self
.
one
_way_foil
.
planet
.
position
,
target
.
planet
.
position
,
dt
)
else
:
else
:
self
.
two
_way_foil
.
planet
.
enabled
=
False
self
.
one
_way_foil
.
planet
.
enabled
=
False
self
.
two_way_foil
.
planet
.
update
=
two
_way_foil_update
self
.
one_way_foil
.
planet
.
update
=
one
_way_foil_update
# # 圆形一向箔显示并设置透明度为0.8
# # 圆形一向箔显示并设置透明度为0.8
self
.
two_way_foil_circl
e
.
planet
.
alpha
=
0.8
self
.
one_way_foil_lin
e
.
planet
.
alpha
=
0.8
self
.
two_way_foil_circl
e
.
planet
.
enabled
=
True
self
.
one_way_foil_lin
e
.
planet
.
enabled
=
True
self
.
two_way_foil_circl
e
.
planet
.
start_scale
=
1
self
.
one_way_foil_lin
e
.
planet
.
start_scale
=
1
# 当前阶段为 stage_02:一向箔压平天体的阶段
# 当前阶段为 stage_02:一向箔压平天体的阶段
self
.
current_stage
=
self
.
stage_02
self
.
current_stage
=
self
.
stage_02
...
@@ -239,12 +237,12 @@ class OneWayFoilSim:
...
@@ -239,12 +237,12 @@ class OneWayFoilSim:
一向箔压平天体(二维化)的阶段
一向箔压平天体(二维化)的阶段
@return:
@return:
"""
"""
self
.
two
_way_foil
.
planet
.
enabled
=
False
self
.
one
_way_foil
.
planet
.
enabled
=
False
# self.sun.two_dim.planet.init_scale += 0.05
# self.sun.two_dim.planet.init_scale += 0.05
# 圆形一向箔不断扩展变大
# 圆形一向箔不断扩展变大
self
.
two
_way_foil
.
planet
.
init_scale
+=
8
self
.
one
_way_foil
.
planet
.
init_scale
+=
8
# 调整天体二维化的时间,一般需要延时,保证扩展和二维化同步的真实效果
# 调整天体二维化的时间,一般需要延时,保证扩展和二维化同步的真实效果
two
_way_delay_times
=
[
0.5
,
# 太阳
one
_way_delay_times
=
[
0.5
,
# 太阳
0.5
,
0.8
,
1.0
,
# 水星 金星 地球
0.5
,
0.8
,
1.0
,
# 水星 金星 地球
1.2
,
2.0
,
3.0
,
# 火星 木星 土星
1.2
,
2.0
,
3.0
,
# 火星 木星 土星
4.0
,
4.5
,
5.5
]
# 天王星 海王星 冥王星
4.0
,
4.5
,
5.5
]
# 天王星 海王星 冥王星
...
@@ -252,20 +250,20 @@ class OneWayFoilSim:
...
@@ -252,20 +250,20 @@ class OneWayFoilSim:
if
isinstance
(
b
,
Obj
):
if
isinstance
(
b
,
Obj
):
# 一向箔不处理
# 一向箔不处理
continue
continue
if
hasattr
(
b
,
"
two
_way_time"
):
if
hasattr
(
b
,
"
one
_way_time"
):
# 一向箔和天体碰撞的时间不为空,则说明已经碰撞
# 一向箔和天体碰撞的时间不为空,则说明已经碰撞
if
b
.
two
_way_time
is
not
None
:
if
b
.
one
_way_time
is
not
None
:
# 如果碰撞后的延时时间到,则进行压平天体处理(二维化)
# 如果碰撞后的延时时间到,则进行压平天体处理(二维化)
if
time
.
time
()
-
b
.
two_way_time
>
two
_way_delay_times
[
idx
]:
if
time
.
time
()
-
b
.
one_way_time
>
one
_way_delay_times
[
idx
]:
self
.
flatten_animation
(
b
)
self
.
flatten_animation
(
b
)
# 一向箔和天体碰撞的时间设置为空,就是说明二维化结束
# 一向箔和天体碰撞的时间设置为空,就是说明二维化结束
b
.
two
_way_time
=
None
b
.
one
_way_time
=
None
elif
two_bodies_colliding
(
self
.
two_way_foil_circl
e
,
b
):
elif
two_bodies_colliding
(
self
.
one_way_foil_lin
e
,
b
):
# 一向箔和天体碰撞,但暂时先不二维化,记下时间,延时二维化
# 一向箔和天体碰撞,但暂时先不二维化,记下时间,延时二维化
b
.
two
_way_time
=
time
.
time
()
b
.
one
_way_time
=
time
.
time
()
# 圆形一向箔不断旋转的效果
# 圆形一向箔不断旋转的效果
self
.
two_way_foil_circl
e
.
planet
.
rotation_z
+=
4
self
.
one_way_foil_lin
e
.
planet
.
rotation_z
+=
4
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
self
,
time_data
):
"""
"""
...
@@ -273,21 +271,21 @@ class OneWayFoilSim:
...
@@ -273,21 +271,21 @@ class OneWayFoilSim:
@param time_data:
@param time_data:
@return:
@return:
"""
"""
# 原始
方形
一向箔飞行的翻转效果
# 原始一向箔飞行的翻转效果
if
self
.
two
_way_foil
.
planet
.
enabled
:
if
self
.
one
_way_foil
.
planet
.
enabled
:
self
.
two
_way_foil
.
planet
.
rotation_x
+=
0.1
self
.
one
_way_foil
.
planet
.
rotation_x
+=
0.1
self
.
two
_way_foil
.
planet
.
rotation_y
+=
1
self
.
one
_way_foil
.
planet
.
rotation_y
+=
1
# # 摄像机始终看向一向箔
# # 摄像机始终看向一向箔
# camera_look_at(self.
two
_way_foil)
# camera_look_at(self.
one
_way_foil)
target
=
self
.
get_target
()
target
=
self
.
get_target
()
if
target
is
not
None
:
if
target
is
not
None
:
if
target
is
self
.
sun
:
if
target
is
self
.
sun
:
# 摄像机始终看向一向箔
# 摄像机始终看向一向箔
camera_look_at
(
self
.
two
_way_foil
)
camera_look_at
(
self
.
one
_way_foil
)
else
:
else
:
# 摄像机始终看向一向箔
# 摄像机始终看向一向箔
camera_look_at
(
self
.
two
_way_foil
,
rotation_z
=
0
)
camera_look_at
(
self
.
one
_way_foil
,
rotation_z
=
0
)
camera
.
position
=
\
camera
.
position
=
\
lerp
(
camera
.
position
,
target
.
planet
.
position
,
0.001
)
lerp
(
camera
.
position
,
target
.
planet
.
position
,
0.001
)
...
@@ -296,7 +294,7 @@ class OneWayFoilSim:
...
@@ -296,7 +294,7 @@ class OneWayFoilSim:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
"""
"""
三体
一向箔场景模拟
一向箔场景模拟
"""
"""
sim
=
OneWayFoilSim
()
sim
=
OneWayFoilSim
()
sim
.
build
()
sim
.
build
()
...
@@ -313,7 +311,7 @@ if __name__ == '__main__':
...
@@ -313,7 +311,7 @@ if __name__ == '__main__':
# position=(0, 2 * AU, -11 * AU),
# position=(0, 2 * AU, -11 * AU),
position
=
(
0
,
5
*
AU
,
-
5
*
AU
),
position
=
(
0
,
5
*
AU
,
-
5
*
AU
),
cosmic_bg
=
''
,
cosmic_bg
=
''
,
bg_music
=
'sounds/no_glory.mp3'
,
#
bg_music='sounds/no_glory.mp3',
show_camera_info
=
False
,
show_camera_info
=
False
,
show_control_info
=
False
,
show_control_info
=
False
,
timer_enabled
=
True
,
timer_enabled
=
True
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录