Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
c157b65e
宇宙模拟器
项目概览
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看板
提交
c157b65e
编写于
10月 23, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
029fba4d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
110 addition
and
46 deletion
+110
-46
sim_scenes/science/earth_season_func.py
sim_scenes/science/earth_season_func.py
+77
-8
sim_scenes/science/earth_seasons.py
sim_scenes/science/earth_seasons.py
+2
-4
sim_scenes/science/earth_seasons_2.py
sim_scenes/science/earth_seasons_2.py
+31
-34
未找到文件。
sim_scenes/science/earth_season_func.py
浏览文件 @
c157b65e
...
...
@@ -11,27 +11,61 @@ from ursina import camera
from
bodies
import
Sun
,
Earth
from
common.consts
import
SECONDS_PER_DAY
,
AU
def
create_trans_earth
(
name
,
text_color
,
position
):
def
create_trans_earth
(
name
,
text_color
,
position
,
texture
=
"earth_transparent.png"
):
"""
创建透明的地球
@param name: 名称
@param text_color: 文字颜色
@param position: 地球的位置
@param texture: 透明地球的纹理图片
@return:
"""
return
Earth
(
name
=
name
,
size_scale
=
5e3
,
texture
=
"earth_transparent.png"
,
# 明的地球纹理
return
Earth
(
name
=
name
,
size_scale
=
5e3
,
texture
=
texture
,
# 明的地球纹理
text_color
=
text_color
,
rotation_speed
=
0
,
init_position
=
position
,
init_velocity
=
[
0
,
0
,
0
]).
set_ignore_gravity
(
True
)
# 忽略重力
def
create_important_pos_earths
():
earth_1
=
create_trans_earth
(
name
=
"春分"
,
text_color
=
(
0
,
255
,
0
),
position
=
[
-
1.05
*
AU
,
0
,
0
])
earth_2
=
create_trans_earth
(
name
=
"夏至"
,
text_color
=
(
255
,
0
,
0
),
position
=
[
0
,
0
,
-
1.05
*
AU
])
earth_3
=
create_trans_earth
(
name
=
"秋分"
,
text_color
=
(
255
,
255
,
0
),
position
=
[
1.05
*
AU
,
0
,
0
])
earth_4
=
create_trans_earth
(
name
=
"冬至"
,
text_color
=
(
0
,
255
,
255
),
position
=
[
0
,
0
,
1.05
*
AU
])
def
create_important_pos_earths
(
texture
=
"earth_transparent.png"
):
"""
创建24节气中4个重要位置的透明地球
@param texture: 透明地球的纹理图片
@return:
"""
earth_1
=
create_trans_earth
(
name
=
"春分"
,
text_color
=
(
0
,
255
,
0
),
position
=
[
-
1.05
*
AU
,
0
,
0
],
texture
=
texture
)
earth_2
=
create_trans_earth
(
name
=
"夏至"
,
text_color
=
(
255
,
0
,
0
),
position
=
[
0
,
0
,
-
1.05
*
AU
],
texture
=
texture
)
earth_3
=
create_trans_earth
(
name
=
"秋分"
,
text_color
=
(
255
,
255
,
0
),
position
=
[
1.05
*
AU
,
0
,
0
],
texture
=
texture
)
earth_4
=
create_trans_earth
(
name
=
"冬至"
,
text_color
=
(
0
,
255
,
255
),
position
=
[
0
,
0
,
1.05
*
AU
],
texture
=
texture
)
return
earth_1
,
earth_2
,
earth_3
,
earth_4
def
create_earth
(
earth_texture
=
"earth_hd.jpg"
,
with_clouds
=
False
,
clouds_texture
=
"transparent_clouds.png"
,
earth_rotation_speed
=
0.5
,
clouds_rotation_speed
=
0.5
):
"""
创建运动的地球(和云层)
@param earth_texture: 地球的纹理图片
@param with_clouds: 是否创建云层
@param clouds_texture: 地球云层的纹理图片
@param earth_rotation_speed: 地球自转速度(为演示效果,自转角速度取0.5度/小时,实际为15度/小时)
@param clouds_rotation_speed: 地球云层的自转速度
@return:
"""
# 运动的地球
earth
=
Earth
(
size_scale
=
5e3
,
texture
=
earth_texture
,
text_color
=
[
255
,
255
,
255
],
rotation_speed
=
earth_rotation_speed
,
init_position
=
[
-
1
*
AU
,
0
,
0
],
init_velocity
=
[
0
,
0
,
-
29.79
])
if
not
with_clouds
:
return
earth
# 创建云层(texture纹理图使用了透明云层的图片,云层的 size_scale 要稍微比地球大一点)
earth_clouds
=
Earth
(
name
=
""
,
texture
=
clouds_texture
,
rotation_speed
=
clouds_rotation_speed
,
show_name
=
False
,
size_scale
=
1.01
*
5e3
,
parent
=
earth
)
return
earth
,
earth_clouds
def
get_solar_terms_angles
():
"""
...
...
@@ -46,4 +80,39 @@ def get_solar_terms_angles():
(
"小暑"
,
157.5
,
172.5
),
(
"大暑"
,
142.5
,
157.5
),
(
"立秋"
,
127.5
,
142.5
),
(
"处暑"
,
112.5
,
127.5
),
(
"白露"
,
97.5
,
112.5
),
(
"秋分"
,
82.5
,
97.5
),
(
"寒露"
,
67.5
,
82.5
),
(
"霜降"
,
52.5
,
67.5
),
(
"立冬"
,
37.5
,
52.5
),
(
"小雪"
,
22.5
,
37.5
),
(
"大雪"
,
7.5
,
22.5
),
(
"冬至"
,
-
7.5
,
7.5
)]
return
solar_terms_angles
\ No newline at end of file
return
solar_terms_angles
def
get_earth_pos_vel_by_term_name
(
term_name
):
"""
根据节气获取地球的初始速度和未知
@param term_name:
@return:
"""
pos_vels
=
{
"立春"
:
{
"pos"
:
[
-
91429152.0
,
0.0
,
119128416.0
],
"vel"
:
[
-
23.56348419189453
,
0.0
,
-
18.03900146484375
]}
,
"雨水"
:
{
"pos"
:
[
-
119206008.0
,
0.0
,
91364824.0
],
"vel"
:
[
-
18.053457260131836
,
0.0
,
-
23.547433853149414
]}
,
"惊蛰"
:
{
"pos"
:
[
-
138759232.0
,
0.0
,
57409412.0
],
"vel"
:
[
-
11.321699142456055
,
0.0
,
-
27.432178497314453
]}
,
"春分"
:
{
"pos"
:
[
-
148826464.0
,
0.0
,
19529740.0
],
"vel"
:
[
-
3.809511184692383
,
0.0
,
-
29.443904876708984
]}
,
"清明"
:
{
"pos"
:
[
-
148717568.0
,
0.0
,
-
19601100.0
],
"vel"
:
[
3.959000825881958
,
0.0
,
-
29.443849563598633
]}
,
"谷雨"
:
{
"pos"
:
[
-
138453296.0
,
0.0
,
-
57392344.0
],
"vel"
:
[
11.474220275878906
,
0.0
,
-
27.430706024169922
]}
,
"立夏"
:
{
"pos"
:
[
-
118763752.0
,
0.0
,
-
91185672.0
],
"vel"
:
[
18.209632873535156
,
0.0
,
-
23.541967391967773
]}
,
"小满"
:
{
"pos"
:
[
-
91024856.0
,
0.0
,
-
118692480.0
],
"vel"
:
[
23.708106994628906
,
0.0
,
-
18.04340171813965
]}
,
"芒种"
:
{
"pos"
:
[
-
57152380.0
,
0.0
,
-
138062688.0
],
"vel"
:
[
27.595821380615234
,
0.0
,
-
11.310075759887695
]}
,
"夏至"
:
{
"pos"
:
[
-
19469878.0
,
0.0
,
-
148008528.0
],
"vel"
:
[
29.608537673950195
,
0.0
,
-
3.801793098449707
]}
,
"小暑"
:
{
"pos"
:
[
19536654.0
,
0.0
,
-
147878576.0
],
"vel"
:
[
29.60844612121582
,
0.0
,
3.9851362705230713
]}
,
"大暑"
:
{
"pos"
:
[
57050156.0
,
0.0
,
-
137724432.0
],
"vel"
:
[
27.59927749633789
,
0.0
,
11.484448432922363
]}
,
"立秋"
:
{
"pos"
:
[
90765216.0
,
0.0
,
-
118185768.0
],
"vel"
:
[
23.70542335510254
,
0.0
,
18.229616165161133
]}
,
"处暑"
:
{
"pos"
:
[
118243424.0
,
0.0
,
-
90663376.0
],
"vel"
:
[
18.207006454467773
,
0.0
,
23.726715087890625
]}
,
"白露"
:
{
"pos"
:
[
137697808.0
,
0.0
,
-
56988980.0
],
"vel"
:
[
11.4738187789917
,
0.0
,
27.613632202148438
]}
,
"秋分"
:
{
"pos"
:
[
147813104.0
,
0.0
,
-
19449096.0
],
"vel"
:
[
3.9687302112579346
,
0.0
,
29.625364303588867
]}
,
"寒露"
:
{
"pos"
:
[
147904608.0
,
0.0
,
19494148.0
],
"vel"
:
[
-
3.810037851333618
,
0.0
,
29.62670135498047
]}
,
"霜降"
:
{
"pos"
:
[
137919376.0
,
0.0
,
57194016.0
],
"vel"
:
[
-
11.329061508178711
,
0.0
,
27.612049102783203
]}
,
"立冬"
:
{
"pos"
:
[
118550400.0
,
0.0
,
91003808.0
],
"vel"
:
[
-
18.058313369750977
,
0.0
,
23.726837158203125
]}
,
"小雪"
:
{
"pos"
:
[
91069912.0
,
0.0
,
118693304.0
],
"vel"
:
[
-
23.554834365844727
,
0.0
,
18.23233985900879
]}
,
"大雪"
:
{
"pos"
:
[
57243580.0
,
0.0
,
138386736.0
],
"vel"
:
[
-
27.450029373168945
,
0.0
,
11.48636245727539
]}
,
"冬至"
:
{
"pos"
:
[
19504978.0
,
0.0
,
148626512.0
],
"vel"
:
[
-
29.46121597290039
,
0.0
,
3.9764606952667236
]}
,
"小寒"
:
{
"pos"
:
[
-
19648712.0
,
0.0
,
148729504.0
],
"vel"
:
[
-
29.460290908813477
,
0.0
,
-
3.801400661468506
]}
,
"大寒"
:
{
"pos"
:
[
-
57462344.0
,
0.0
,
138679984.0
],
"vel"
:
[
-
27.450258255004883
,
0.0
,
-
11.3037691116333
]}
}
return
pos_vels
.
get
(
term_name
,
None
)
sim_scenes/science/earth_seasons.py
浏览文件 @
c157b65e
...
...
@@ -11,7 +11,7 @@ from ursina import camera
from
bodies
import
Sun
,
Earth
from
common.consts
import
SECONDS_PER_DAY
,
AU
from
sim_scenes.func
import
ursina_run
,
camera_look_at
from
sim_scenes.science.earth_season_func
import
create_important_pos_earths
,
get_solar_terms_angles
from
sim_scenes.science.earth_season_func
import
create_important_pos_earths
,
get_solar_terms_angles
,
create_earth
from
simulators.ursina.entities.body_timer
import
TimeData
,
BodyTimer
from
simulators.ursina.ursina_event
import
UrsinaEvent
...
...
@@ -23,9 +23,7 @@ if __name__ == '__main__':
# 在 4 个节气的位置创建固定不动的透明地球
earth_1
,
earth_2
,
earth_3
,
earth_4
=
create_important_pos_earths
()
# 运动的地球
earth
=
Earth
(
size_scale
=
5e3
,
texture
=
"earth_hd.jpg"
,
text_color
=
[
255
,
255
,
255
],
rotation_speed
=
0.5
,
# 为演示效果,自转角速度取0.5度/小时,实际为15度/小时
init_position
=
[
-
1
*
AU
,
0
,
0
],
init_velocity
=
[
0
,
0
,
-
29.79
])
earth
=
create_earth
()
# 地球立春的位置和速度
earth
.
init_position
=
[
-
9.1507536e+07
,
0.0000000e+00
,
1.1907757e+08
]
...
...
sim_scenes/science/earth_seasons_2.py
浏览文件 @
c157b65e
...
...
@@ -11,26 +11,11 @@ from ursina import camera
from
bodies
import
Sun
,
Earth
from
common.consts
import
SECONDS_PER_DAY
,
AU
from
sim_scenes.func
import
ursina_run
,
camera_look_at
,
create_sphere_sky
from
sim_scenes.science.earth_season_func
import
get_solar_terms_angles
,
create_important_pos_earths
from
sim_scenes.science.earth_season_func
import
get_solar_terms_angles
,
create_important_pos_earths
,
\
get_earth_pos_vel_by_term_name
,
create_earth
from
simulators.ursina.entities.body_timer
import
TimeData
,
BodyTimer
from
simulators.ursina.ursina_event
import
UrsinaEvent
def
create_earth
(
name
,
text_color
,
position
):
"""
创建透明的地球
@param name: 名称
@param text_color: 文字颜色
@param position: 地球的位置
@return:
"""
earth
=
Earth
(
name
=
name
,
size_scale
=
5e3
,
texture
=
"earth_transparent.png"
,
# 明的地球纹理
text_color
=
text_color
,
rotation_speed
=
0
,
init_position
=
position
,
init_velocity
=
[
0
,
0
,
0
]).
set_ignore_gravity
(
True
)
# 忽略重力
return
earth
if
__name__
==
'__main__'
:
"""
摄像机以太阳的视角看地球(四季和24节气)
...
...
@@ -39,19 +24,14 @@ if __name__ == '__main__':
# 在 4 个节气的位置创建固定不动的透明地球
earth_1
,
earth_2
,
earth_3
,
earth_4
=
create_important_pos_earths
()
# 运动的地球
earth
=
Earth
(
size_scale
=
5e3
,
texture
=
"earth-huge.jpg"
,
text_color
=
[
255
,
255
,
255
],
rotation_speed
=
0.5
,
# 为演示效果,自转角速度取0.5度/小时,实际为15度/小时
init_position
=
[
-
1
*
AU
,
0
,
0
],
init_velocity
=
[
0
,
0
,
-
29.79
])
# 创建运动的地球和云层
earth
,
earth_clouds
=
create_earth
(
with_clouds
=
True
,
earth_rotation_speed
=
1.0
,
clouds_rotation_speed
=
1.2
)
# 创建云层(texture纹理图使用了透明云层的图片,云层的 size_scale 要稍微比地球大一点)
earth_clouds
=
Earth
(
name
=
""
,
texture
=
"transparent_clouds.png"
,
rotation_speed
=
0.51
,
show_name
=
False
,
size_scale
=
1.01
*
5e3
,
parent
=
earth
)
pos_vel
=
get_earth_pos_vel_by_term_name
(
"寒露"
)
# 地球立春的位置和速度
earth
.
init_position
=
[
-
9.1507536e+07
,
0.0000000e+00
,
1.1907757e+08
]
earth
.
init_velocity
=
[
-
23.550875
,
0.
,
-
18.05398
]
if
pos_vel
is
not
None
:
earth
.
init_position
=
pos_vel
[
"pos"
]
earth
.
init_velocity
=
pos_vel
[
"vel"
]
earth
.
rotate_axis_color
=
(
255
,
255
,
50
)
earth
.
rotate_axis_scale
=
0.62
...
...
@@ -93,6 +73,27 @@ if __name__ == '__main__':
e
.
name_text
.
enabled
=
True
def
log_earth_pos_vel
(
term_name
):
"""
记录地球每个节气的开始的初始位置和速度
@param term_name:
@return:
"""
if
not
hasattr
(
earth
,
"last_term_name"
):
earth
.
last_term_name
=
""
if
earth
.
last_term_name
!=
term_name
:
pos
=
earth
.
position
vel
=
earth
.
velocity
print
(
f
'{{"
{
term_name
}
": {{'
f
'"pos": [
{
pos
[
0
]
}
,
{
pos
[
1
]
}
,
{
pos
[
2
]
}
], '
f
'"vel": [
{
vel
[
0
]
}
,
{
vel
[
1
]
}
,
{
vel
[
2
]
}
]'
f
'}}}}'
)
earth
.
last_term_name
=
term_name
def
on_timer_changed
(
time_data
:
TimeData
):
# 摄像机始终看向移动的地球
camera_look_at
(
earth
,
rotation_z
=
0
)
...
...
@@ -102,13 +103,9 @@ if __name__ == '__main__':
term_name
=
info
[
0
]
# 控制4个透明地球文本是否显示,防止地球文字的叠加
earth_text_display
(
term_name
)
log_earth_pos_vel
(
term_name
)
# 地球名称文字显示为相应的节气
earth
.
name_text
.
text
=
term_name
# if term_name == "立春": # 找到立春的位置和速度
# print("position", earth.position)
# print("velocity", earth.velocity)
# print(camera.rotation_y)
# 订阅事件后,上面2个函数功能才会起作用
...
...
@@ -121,7 +118,7 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_DAY
*
2
,
ursina_run
(
bodies
,
SECONDS_PER_DAY
/
2
,
position
=
(
0
,
0
,
0
),
# 摄像机和太阳是相同位置
cosmic_bg
=
''
,
show_grid
=
False
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录