Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
8e7a7199
宇宙模拟器
项目概览
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看板
提交
8e7a7199
编写于
11月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
d437f278
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
151 addition
and
77 deletion
+151
-77
sim_scenes/solar_system/halley_comet_sim.py
sim_scenes/solar_system/halley_comet_sim.py
+140
-75
sim_scenes/universe_sim_scenes.py
sim_scenes/universe_sim_scenes.py
+2
-0
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+9
-2
未找到文件。
sim_scenes/solar_system/halley_comet_sim.py
浏览文件 @
8e7a7199
...
@@ -151,8 +151,9 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -151,8 +151,9 @@ class HalleyCometSim(HalleyCometSimBase):
scale
=
scale
,
alpha
=
1.0
,
background
=
background
scale
=
scale
,
alpha
=
1.0
,
background
=
background
)
)
label
.
set_light_off
()
label
.
set_light_off
()
self
.
last_year
=
year
def
set
_comet_trail_alpha
(
self
,
distance_sun
):
def
update
_comet_trail_alpha
(
self
,
distance_sun
):
"""
"""
根据彗哈雷星和太阳的距离,设置彗星尾巴的透明度来模仿接近太阳有慧尾,离开太阳到一定距离就渐渐消失
根据彗哈雷星和太阳的距离,设置彗星尾巴的透明度来模仿接近太阳有慧尾,离开太阳到一定距离就渐渐消失
@param distance_sun: 彗哈雷星和太阳的距离
@param distance_sun: 彗哈雷星和太阳的距离
...
@@ -204,6 +205,12 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -204,6 +205,12 @@ class HalleyCometSim(HalleyCometSimBase):
return
get_run_speed_factor
()
*
value
return
get_run_speed_factor
()
*
value
def
camera_move
(
self
,
dt
):
def
camera_move
(
self
,
dt
):
"""
摄像机移动控制
@param dt:
@return:
"""
# 摄像机移动控制数据
camera_move_infos
=
[
camera_move_infos
=
[
# 条件:年份
# 条件:年份
# 移动的信息:
# 移动的信息:
...
@@ -229,65 +236,95 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -229,65 +236,95 @@ class HalleyCometSim(HalleyCometSimBase):
@param time_data:
@param time_data:
@return:
@return:
"""
"""
dt
=
time_data
.
get_datetime
(
str
(
self
.
start_time
))
dt
=
time_data
.
get_datetime
(
self
.
start_time
)
year
=
dt
.
strftime
(
"%Y"
)
# 摄像机看向哈雷彗星
camera_look_at
(
self
.
halley_comet
,
rotation_z
=
0
)
camera_look_at
(
self
.
halley_comet
,
rotation_z
=
0
)
self
.
camera_move
(
dt
)
time_total_hours
=
time_data
.
total_hours
if
hasattr
(
self
,
"halley_comet"
):
if
not
hasattr
(
self
,
"last_total_hours"
):
if
self
.
halley_comet
.
planet
.
enabled
:
self
.
last_total_hours
=
time_total_hours
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
self
.
update_halley_comet_info
(
dt
)
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
if
len
(
trail_keys
)
>
0
:
last_trail
=
list
(
trail_keys
)[
-
1
]
if
hasattr
(
last_trail
,
"entity_infos"
):
last_trail
.
entity_infos
[
"distance_from_sun"
]
=
d_sun
last_trail
.
entity_infos
[
"distance_from_earth"
]
=
d_earth
last_trail
.
entity_infos
[
"time"
]
=
dt
.
strftime
(
"%Y-%m-%d"
)
pos
=
self
.
halley_comet
.
planet
.
position
# 每隔一段时间运行一次更新(不要太频繁更新,会导致摄像机抖动)
if
time_total_hours
-
self
.
last_total_hours
>
100
:
self
.
camera_move
(
dt
)
self
.
update_halley_comet_info
(
dt
)
self
.
update_ui
(
time_data
,
dt
)
# 记录最后更新的总耗时(小时)
self
.
last_total_hours
=
time_total_hours
import
copy
def
check_create_year_label
(
self
,
last_trail
,
dt
):
"""
检测并创建年标签
@param last_trail:
@param dt:
@return:
"""
if
last_trail
is
None
:
return
import
copy
year
=
dt
.
strftime
(
"%Y"
)
pos
=
self
.
halley_comet
.
planet
.
position
# 里程碑标签
if
self
.
show_milestone_lable
(
last_trail
,
dt
):
if
self
.
show_milestone_lable
(
last_trail
,
dt
):
pass
pass
elif
not
hasattr
(
self
,
"last_year"
):
elif
not
hasattr
(
self
,
"last_year"
):
self
.
create_year_label
(
last_trail
,
year
,
pos
)
# 第一次运行,则创建“年标签”
elif
self
.
last_year
!=
year
:
if
not
hasattr
(
self
,
"last_label_pos"
):
self
.
create_year_label
(
last_trail
,
year
,
pos
)
self
.
create_year_label
(
last_trail
,
year
,
pos
)
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
else
:
elif
self
.
last_year
!=
year
:
# 防止标签非常紧密
if
hasattr
(
self
,
"last_label_pos"
):
# 防止“年标签”显示非常紧密
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
last_label_pos
)
d
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
last_label_pos
)
if
d
>
2
*
AU
:
if
d
>
2
*
AU
:
self
.
create_year_label
(
last_trail
,
year
,
pos
)
self
.
create_year_label
(
last_trail
,
year
,
pos
)
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
self
.
last_label_pos
=
copy
.
deepcopy
(
self
.
halley_comet
.
position
)
self
.
last_year
=
year
def
update_halley_comet_info
(
self
,
dt
):
"""
更新哈雷彗星的信息
@param dt:
@return:
"""
# 哈雷彗星面向太阳,这样彗尾就远离太阳的方向
self
.
halley_comet
.
planet
.
look_at
(
self
.
sun
.
planet
)
# 哈雷彗星离太阳最近的点称为 "perihelion of Halley's Comet"(近日点:comet_peri),
# 计算哈雷彗星与太阳、地球的距离
if
not
hasattr
(
self
,
"comet_peri"
):
d_sun
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
sun
.
position
)
self
.
comet_peri
=
d_sun
d_earth
=
calculate_distance
(
self
.
halley_comet
.
position
,
self
.
earth
.
position
)
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
# 哈雷彗星所有轨迹线(注意不是彗尾)
elif
d_sun
<
self
.
comet_peri
:
trail_keys
=
self
.
halley_comet
.
planet
.
trails
.
keys
()
self
.
comet_peri
=
d_sun
# 哈雷彗星有轨迹线
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
if
len
(
trail_keys
)
>
0
:
# 找的最后的轨迹线
last_trail
=
list
(
trail_keys
)[
-
1
]
if
hasattr
(
last_trail
,
"entity_infos"
):
# 如果是轨迹球,则轨迹球会记录当前位置与太阳、地球的距离,并记录了当前的日期
last_trail
.
entity_infos
[
"distance_from_sun"
]
=
d_sun
last_trail
.
entity_infos
[
"distance_from_earth"
]
=
d_earth
last_trail
.
entity_infos
[
"time"
]
=
dt
.
strftime
(
"%Y-%m-%d"
)
# 哈雷彗星离太阳最远的点称为 "aphelion of Halley's Comet"(远日点)
# 检测并再轨迹线上创建年标签
if
not
hasattr
(
self
,
"comet_aphel"
):
self
.
check_create_year_label
(
last_trail
,
dt
)
self
.
comet_aphel
=
d_sun
self
.
comet_aphel_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
elif
d_sun
>
self
.
comet_aphel
:
self
.
comet_aphel
=
d_sun
self
.
comet_aphel_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
self
.
set_comet_trail_alpha
(
d_sun
)
# 更新彗星尾巴的透明度
self
.
update_comet_trail_alpha
(
d_sun
)
# 计算和更新近日点数据
self
.
update_comet_peri
(
d_sun
,
dt
)
# 计算和更新远日点数据
self
.
update_comet_aphel
(
d_sun
,
dt
)
# 更新文字信息面板
self
.
update_text_panel
(
d_sun
)
def
update_text_panel
(
self
,
d_sun
):
"""
更新文字信息面板
@param d_sun:
@return:
"""
panel_text
=
"哈雷彗星:
\n\n
距离太阳:%.3f
\t
AU"
%
(
d_sun
/
AU
)
panel_text
=
"哈雷彗星:
\n\n
距离太阳:%.3f
\t
AU"
%
(
d_sun
/
AU
)
panel_text
+=
"
\n\n
离日最远:%.3f
\t
AU"
%
(
self
.
comet_aphel
/
AU
)
panel_text
+=
"
\n\n
离日最远:%.3f
\t
AU"
%
(
self
.
comet_aphel
/
AU
)
panel_text
+=
"
\n\n
离日最近:%.3f
\t
AU"
%
(
self
.
comet_peri
/
AU
)
panel_text
+=
"
\n\n
离日最近:%.3f
\t
AU"
%
(
self
.
comet_peri
/
AU
)
...
@@ -296,22 +333,50 @@ class HalleyCometSim(HalleyCometSimBase):
...
@@ -296,22 +333,50 @@ class HalleyCometSim(HalleyCometSimBase):
self
.
text_panel
.
text
=
panel_text
self
.
text_panel
.
text
=
panel_text
time_total_hours
=
time_data
.
total_hours
def
update_comet_aphel
(
self
,
d_sun
,
dt
):
"""
计算和更新远日点数据
@param d_sun:
@param dt:
@return:
"""
# 哈雷彗星离太阳最远的点称为 "aphelion of Halley's Comet"(远日点)
if
not
hasattr
(
self
,
"comet_aphel"
):
self
.
comet_aphel
=
d_sun
self
.
comet_aphel_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
elif
d_sun
>
self
.
comet_aphel
:
self
.
comet_aphel
=
d_sun
self
.
comet_aphel_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
if
not
hasattr
(
self
,
"last_total_hours"
):
def
update_comet_peri
(
self
,
d_sun
,
dt
):
self
.
last_total_hours
=
time_total_hours
"""
计算和更新近日点数据
@param d_sun:
@param dt:
@return:
"""
# 哈雷彗星离太阳最近的点称为 "perihelion of Halley's Comet"(近日点:comet_peri),
if
not
hasattr
(
self
,
"comet_peri"
):
self
.
comet_peri
=
d_sun
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
elif
d_sun
<
self
.
comet_peri
:
self
.
comet_peri
=
d_sun
self
.
comet_peri_dt
=
dt
.
strftime
(
"%Y-%m-%d"
)
# 每个一段时间运行一次更新(不要太频繁更新,会导致摄像机抖动)
def
update_ui
(
self
,
time_data
,
dt
):
if
time_total_hours
-
self
.
last_total_hours
>
100
:
"""
更新UI,包含天体的位置、时钟、轨道的位置
@param time_data:
@param dt:
@return:
"""
# 更新天体的位置
# 更新天体的位置
self
.
set_bodies_position
(
time_data
)
self
.
set_bodies_position
(
time_data
)
# 更新时钟
# 更新时钟
self
.
show_clock
(
dt
)
self
.
show_clock
(
dt
)
# 更新轨道的位置
# 更新轨道的位置(TODO:短时间可以忽略)
for
i
,
orbit_line
in
enumerate
(
self
.
orbit_lines
):
# for i, orbit_line in enumerate(self.orbit_lines):
orbit_line
.
position
=
self
.
sun
.
planet
.
position
# orbit_line.position = self.sun.planet.position
self
.
last_total_hours
=
time_total_hours
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
sim_scenes/universe_sim_scenes.py
浏览文件 @
8e7a7199
...
@@ -29,3 +29,5 @@ class UniverseSimScenes:
...
@@ -29,3 +29,5 @@ class UniverseSimScenes:
# self.set_window_size((int(1920 * r), int(1080 * r)))
# self.set_window_size((int(1920 * r), int(1080 * r)))
# self.set_window_size((2376, 1080))
# self.set_window_size((2376, 1080))
# self.set_window_size((520, 540), fullscreen=False)
# self.set_window_size((520, 540), fullscreen=False)
simulators/ursina/entities/body_timer.py
浏览文件 @
8e7a7199
...
@@ -59,15 +59,21 @@ class TimeData:
...
@@ -59,15 +59,21 @@ class TimeData:
else
:
else
:
self
.
time_text
=
f
'
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
self
.
time_text
=
f
'
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
def
get_datetime
(
self
,
init_datetime
):
def
get_datetime
(
self
,
init_datetime
):
"""
根据初始化的时间,获取当前北京时间
@param init_datetime:
@return:
"""
import
datetime
import
datetime
if
not
isinstance
(
init_datetime
,
str
):
init_datetime
=
str
(
init_datetime
)
# UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ"
# UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ"
if
len
(
init_datetime
)
==
19
:
if
len
(
init_datetime
)
==
19
:
init_datetime
=
init_datetime
+
".000"
init_datetime
=
init_datetime
+
".000"
UTC
=
datetime
.
datetime
.
strptime
(
init_datetime
+
"Z"
,
"%Y-%m-%d %H:%M:%S.%fZ"
)
UTC
=
datetime
.
datetime
.
strptime
(
init_datetime
+
"Z"
,
"%Y-%m-%d %H:%M:%S.%fZ"
)
# BJS_format = "%Y-%m-%d %H:%M:%S"
# BJS_format = "%Y-%m-%d %H:%M:%S"
BJS
=
UTC
+
datetime
.
timedelta
(
hours
=
8
+
self
.
total_hours
)
BJS
=
UTC
+
datetime
.
timedelta
(
hours
=
8
+
self
.
total_hours
)
# BJS = BJS.strftime(BJS_format)
# BJS = BJS.strftime(BJS_format)
# dt = datetime(init_datetime)
# dt = datetime(init_datetime)
return
BJS
return
BJS
...
@@ -89,6 +95,7 @@ class AppTimeUtil:
...
@@ -89,6 +95,7 @@ class AppTimeUtil:
"""
"""
应用计数器工具类
应用计数器工具类
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
arrival_time
=
-
1
self
.
arrival_time
=
-
1
self
.
current_time
=
0
self
.
current_time
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录