Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
8449bb65
宇宙模拟器
项目概览
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看板
提交
8449bb65
编写于
3月 14, 2024
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
18248d3d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
34 deletion
+76
-34
sim_scenes/sci_pop/sun_earth_moon.py
sim_scenes/sci_pop/sun_earth_moon.py
+76
-34
未找到文件。
sim_scenes/sci_pop/sun_earth_moon.py
浏览文件 @
8449bb65
...
@@ -32,13 +32,15 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -32,13 +32,15 @@ class SunEarthMoonSim(UniverseSimScenes):
self
.
bodies
=
None
self
.
bodies
=
None
self
.
orbit_lines
=
[]
self
.
orbit_lines
=
[]
self
.
run_finished
=
False
self
.
run_finished
=
False
# 地球自转一圈是23小时56分4秒,公转一圈是365天6小时9分9秒 365.25
self
.
earth_revolution_days
=
365.25
+
(
9
*
60
+
9
)
/
60
/
60
/
24
def
build_bodies
(
self
):
def
build_bodies
(
self
):
# region 构建太阳系
# region 构建太阳系
self
.
sun
=
Sun
(
size_scale
=
6e1
,
texture
=
"sun_light.jpg"
)
self
.
sun
=
Sun
(
size_scale
=
6e1
,
texture
=
"sun_light.jpg"
)
self
.
moon
=
Moon
(
size_scale
=
18
e2
)
self
.
moon
=
Moon
(
size_scale
=
22
e2
)
self
.
earth
=
Earth
(
size_scale
=
9
e2
,
show_trail
=
False
)
self
.
earth
=
Earth
(
size_scale
=
10
e2
,
show_trail
=
False
)
self
.
earth_start
=
Earth
(
size_scale
=
9e2
,
show_trail
=
False
,
rotation_speed
=
0
)
self
.
earth_start
=
Earth
(
size_scale
=
9
.5
e2
,
show_trail
=
False
,
rotation_speed
=
0
)
self
.
bodies
=
[
self
.
sun
,
self
.
earth
,
self
.
moon
,
self
.
earth_start
]
self
.
bodies
=
[
self
.
sun
,
self
.
earth
,
self
.
moon
,
self
.
earth_start
]
...
@@ -63,34 +65,61 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -63,34 +65,61 @@ class SunEarthMoonSim(UniverseSimScenes):
@return:
@return:
"""
"""
if
self
.
run_finished
:
if
self
.
run_finished
:
# self.earth.planet.rotation_y = self.earth.planet.last_rotation_y
# self.moon.planet.rotation_y = self.moon.planet.last_rotation_y
# self.sun.planet.rotation_y = self.sun.planet.last_rotation_y
return
return
dt
=
time_data
.
get_datetime
(
self
.
start_time
)
from
ursina
import
distance
if
dt
.
year
==
2025
:
if
time_data
.
total_days
>=
self
.
earth_revolution_days
:
self
.
run_finished
=
True
self
.
run_finished
=
True
self
.
earth
.
rotation_speed
=
0
# self.earth.planet.rotation_speed = 0
# self.moon.planet.rotation_speed = 0
# self.sun.planet.rotation_speed = 0
#
# self.earth.planet.last_rotation_y = self.earth.planet.rotation_y
# self.moon.planet.last_rotation_y = self.moon.planet.rotation_y
# self.sun.planet.last_rotation_y = self.sun.planet.rotation_y
UrsinaConfig
.
run_speed_factor
=
0.00001
*
24
self
.
update_text_panel
(
time_data
)
return
return
if
dt
.
month
<
11
:
dt
=
time_data
.
get_datetime
(
self
.
start_time
)
UrsinaConfig
.
run_speed_factor
=
200
# if dt.year == self.current_year + 1:
elif
UrsinaConfig
.
run_speed_factor
>
20
:
UrsinaConfig
.
run_speed_factor
=
20
if
dt
.
month
<
12
:
UrsinaConfig
.
run_speed_factor
=
200
*
24
elif
UrsinaConfig
.
run_speed_factor
>
20
*
24
:
UrsinaConfig
.
run_speed_factor
=
20
*
24
if
dt
.
month
>=
12
and
dt
.
day
>=
31
:
if
dt
.
month
>=
12
and
dt
.
day
>=
31
:
UrsinaConfig
.
run_speed_factor
-=
0.1
if
dt
.
hour
>
20
:
elif
dt
.
month
>=
12
and
dt
.
day
>=
28
and
UrsinaConfig
.
run_speed_factor
>=
1.1
:
UrsinaConfig
.
run_speed_factor
-=
0.00001
*
24
UrsinaConfig
.
run_speed_factor
-=
0.8
if
UrsinaConfig
.
run_speed_factor
<
0.00001
*
24
:
UrsinaConfig
.
run_speed_factor
=
0.00001
*
24
else
:
UrsinaConfig
.
run_speed_factor
-=
0.00001
*
24
elif
dt
.
month
>=
12
and
dt
.
day
>=
28
and
UrsinaConfig
.
run_speed_factor
>=
1.1
*
24
:
UrsinaConfig
.
run_speed_factor
-=
0.65
*
24
# elif dt.month >= 12 :#and dt.day > 20:
# elif dt.month >= 12 :#and dt.day > 20:
# UrsinaConfig.run_speed_factor -= 1
# UrsinaConfig.run_speed_factor -= 1
if
UrsinaConfig
.
run_speed_factor
<
0.1
:
UrsinaConfig
.
run_speed_factor
=
0.1
UrsinaConfig
.
run_speed_factor
=
round
(
UrsinaConfig
.
run_speed_factor
,
2
)
UrsinaConfig
.
run_speed_factor
=
round
(
UrsinaConfig
.
run_speed_factor
,
2
)
self
.
set_bodies_position
(
time_data
)
self
.
set_bodies_position
(
time_data
)
self
.
update_text_panel
(
dt
)
self
.
update_text_panel
(
time_data
)
# if dt.month >= 12:
# dd = distance(self.earth.position, self.earth_start.position)
# # 225000388
# if dd < 1000000:
# self.run_finished = True
# self.earth.planet.rotation_speed = 0
# return
def
create_orbit_line
(
self
,
center_body
,
body
,
start_time
,
alpha
=
0.2
):
def
create_orbit_line
(
self
,
center_body
,
body
,
start_time
,
alpha
=
0.2
):
import
math
import
math
...
@@ -148,7 +177,7 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -148,7 +177,7 @@ class SunEarthMoonSim(UniverseSimScenes):
# camera_move_update()
# camera_move_update()
# camera_move_to_target_update()
# camera_move_to_target_update()
def
show_clock
(
self
,
dt
):
def
show_clock
(
self
,
time_data
):
"""
"""
显示时钟
显示时钟
@param dt: 时间 datetime
@param dt: 时间 datetime
...
@@ -158,30 +187,42 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -158,30 +187,42 @@ class SunEarthMoonSim(UniverseSimScenes):
# position, origin = (0, .25), (0, 0),
# position, origin = (0, .25), (0, 0),
# else:
# else:
from
ursina
import
window
from
ursina
import
window
total_days
=
round
(
time_data
.
total_days
,
2
)
if
total_days
>
self
.
earth_revolution_days
:
total_days
=
self
.
earth_revolution_days
seconds
=
self
.
earth_revolution_days
*
24
*
60
*
60
time_data
=
TimeData
(
seconds
,
"seconds"
,
seconds
)
dt
=
time_data
.
get_datetime
(
self
.
start_time
)
aspect_ratio
=
window
.
aspect_ratio
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.15
,
-
0.45
),
(
-
0.05
,
0.1
),
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.15
,
-
0.45
),
(
-
0.05
,
0.1
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d'
),
# ControlUI.current_ui.show_message(dt.strftime('%Y-%m-%d'),
position
=
position
,
# position=position,
origin
=
origin
,
# origin=origin,
# font="verdana.ttf",
# # font="verdana.ttf",
font
=
"fonts/Digital-7Mono.TTF"
,
# font="fonts/Digital-7Mono.TTF",
font_scale
=
2
,
# font_scale=2,
font_color
=
(
0
,
255
,
0
),
# font_color=(0, 255, 0),
close_time
=-
1
)
# close_time=-1)
self
.
text_panel
.
text
=
"时间:
\n
"
+
dt
.
strftime
(
'%Y-%m-%d %H:%M'
)
+
"
\n
"
+
\
self
.
text_panel
.
text
=
"
\n
日期时间:
\n
"
+
dt
.
strftime
(
'%Y-%m-%d %H:%M'
)
+
"
\n\n
"
+
\
"运行速度:"
+
str
(
UrsinaConfig
.
run_speed_factor
)
+
"
\n
"
"天数:"
+
str
(
round
(
total_days
,
3
))
# "运行速度:" + str(UrsinaConfig.run_speed_factor) + "\n" + \
def
update_text_panel
(
self
,
dt
):
# "天数:" + str(round(total_days, 3))
def
update_text_panel
(
self
,
time_data
):
"""
"""
更新文字信息面板
更新文字信息面板
@param d_sun:
@param d_sun:
@return:
@return:
"""
"""
# panel_text = "时间" #"\n\n当前速度:%s km/s" % "{:.3f}".format(velocity).rjust(6, "0")
# panel_text = "时间" #"\n\n当前速度:%s km/s" % "{:.3f}".format(velocity).rjust(6, "0")
#
#
# self.text_panel.text = panel_text
# self.text_panel.text = panel_text
self
.
show_clock
(
dt
)
self
.
show_clock
(
time_data
)
def
on_ready
(
self
):
def
on_ready
(
self
):
"""
"""
...
@@ -205,10 +246,11 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -205,10 +246,11 @@ class SunEarthMoonSim(UniverseSimScenes):
# self.text_panel = create_text_panel(font="fonts/sanjixiaozhuanti.ttf", font_scale=1.5)
# self.text_panel = create_text_panel(font="fonts/sanjixiaozhuanti.ttf", font_scale=1.5)
self
.
text_panel
=
create_text_panel
(
font
=
"fonts/DroidSansFallback.ttf"
,
font_scale
=
1.3
)
self
.
text_panel
=
create_text_panel
(
font
=
"fonts/DroidSansFallback.ttf"
,
font_scale
=
1.3
)
def
run
(
self
,
start_time
=
'202
4
-01-01 00:00:00'
):
def
run
(
self
,
start_time
=
'202
3
-01-01 00:00:00'
):
self
.
build_bodies
()
self
.
build_bodies
()
from
astropy.time
import
Time
from
astropy.time
import
Time
from
datetime
import
datetime
from
datetime
import
datetime
self
.
current_year
=
int
(
start_time
[
0
:
4
])
start_time
=
Time
(
datetime
.
strptime
(
start_time
+
'+0800'
,
'%Y-%m-%d %H:%M:%S%z'
),
start_time
=
Time
(
datetime
.
strptime
(
start_time
+
'+0800'
,
'%Y-%m-%d %H:%M:%S%z'
),
format
=
'datetime'
)
format
=
'datetime'
)
...
@@ -220,7 +262,7 @@ class SunEarthMoonSim(UniverseSimScenes):
...
@@ -220,7 +262,7 @@ class SunEarthMoonSim(UniverseSimScenes):
# init_bodies_reality_pos_vels(self.bodies, start_time)
# init_bodies_reality_pos_vels(self.bodies, start_time)
self
.
start_time
=
start_time
self
.
start_time
=
start_time
ursina_run
(
self
.
bodies
,
ursina_run
(
self
.
bodies
,
SECONDS_PER_DAY
,
SECONDS_PER_DAY
/
24
,
position
=
(
0
,
3.5
*
AU
,
-
AU
),
position
=
(
0
,
3.5
*
AU
,
-
AU
),
gravity_works
=
False
,
gravity_works
=
False
,
cosmic_bg
=
''
,
cosmic_bg
=
''
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录