Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
d312a416
宇宙模拟器
项目概览
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看板
提交
d312a416
编写于
11月 27, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
e4ee649c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
31 deletion
+55
-31
bodies/sun.py
bodies/sun.py
+1
-1
sim_scenes/fiction/earth_orbit_stopped.py
sim_scenes/fiction/earth_orbit_stopped.py
+37
-23
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+4
-4
simulators/ursina/entities/timer.py
simulators/ursina/entities/timer.py
+13
-3
未找到文件。
bodies/sun.py
浏览文件 @
d312a416
...
@@ -45,7 +45,7 @@ class Sun(FixedStar):
...
@@ -45,7 +45,7 @@ class Sun(FixedStar):
}
}
super
().
__init__
(
**
params
)
super
().
__init__
(
**
params
)
self
.
glows
=
(
12
,
1.015
,
0.08
)
self
.
glows
=
(
12
,
1.015
,
0.08
)
self
.
glows
=
(
4
,
1.005
,
0.1
)
#
self.glows = (4, 1.005, 0.1)
@
property
@
property
def
is_fixed_star
(
self
):
def
is_fixed_star
(
self
):
...
...
sim_scenes/fiction/earth_orbit_stopped.py
浏览文件 @
d312a416
...
@@ -10,7 +10,7 @@ from bodies import Sun, Earth, Mercury, Venus
...
@@ -10,7 +10,7 @@ from bodies import Sun, Earth, Mercury, Venus
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
common.func
import
calculate_distance
,
get_acceleration_info
from
common.func
import
calculate_distance
,
get_acceleration_info
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
,
two_bodies_colliding
,
set_camera_parent
,
\
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
,
two_bodies_colliding
,
set_camera_parent
,
\
create_text_panel
create_text_panel
,
create_sphere_sky
from
bodies.body
import
AU
from
bodies.body
import
AU
from
sim_scenes.universe_sim_scenes
import
UniverseSimScenes
from
sim_scenes.universe_sim_scenes
import
UniverseSimScenes
from
simulators.ursina.entities.body_timer
import
BodyTimer
,
TimeData
from
simulators.ursina.entities.body_timer
import
BodyTimer
,
TimeData
...
@@ -33,7 +33,9 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
...
@@ -33,7 +33,9 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
sun
=
Sun
(
init_position
=
[
0
,
0
,
0
],
size_scale
=
1
)
self
.
sun
=
Sun
(
init_position
=
[
0
,
0
,
0
],
size_scale
=
1
)
self
.
earth
=
Earth
(
init_position
=
[
0
,
0
,
-
AU
],
# texture="earth2.jpg",
# self.glows = (4, 1.005, 0.1)
# self.sun = Sun(init_position=[0, 0, 0], color=(255, 255, 200), size_scale=1, texture="fixed_star.png")
self
.
earth
=
Earth
(
init_position
=
[
0
,
0
,
-
AU
],
texture
=
"earth_hd.jpg"
,
init_velocity
=
[
0
,
self
.
EARTH_INIT_VELOCITY
,
0
],
init_velocity
=
[
0
,
self
.
EARTH_INIT_VELOCITY
,
0
],
size_scale
=
1
).
set_light_disable
(
True
)
size_scale
=
1
).
set_light_disable
(
True
)
# 水星轨道半径
# 水星轨道半径
...
@@ -65,17 +67,17 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
...
@@ -65,17 +67,17 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
# 显示板信息模板
# 显示板信息模板
self
.
arrived_info
=
" 距离太阳:${distance}
\n\n
地球速度:${velocity}
\n\n
地球加速度:${acceleration}
\n\n
"
self
.
arrived_info
=
" 距离太阳:${distance}
\n\n
地球速度:${velocity}
\n\n
地球加速度:${acceleration}
\n\n
"
def
create_orbit_line
(
self
,
radius
,
color
):
#
def create_orbit_line(self, radius, color):
"""
#
"""
创建行星轨道线
#
创建行星轨道线
@param radius: 以太阳中心为中心点的半径
#
@param radius: 以太阳中心为中心点的半径
@param color: 颜色
#
@param color: 颜色
@return:
#
@return:
"""
#
"""
orbit_line
=
create_circle_line
(
parent
=
self
.
sun
,
radius
=
radius
,
thickness
=
5
,
color
=
color
,
alpha
=
0.3
)
# orbit_line = create_circle_line(parent=self.sun, radius=radius, thickness=3, color=color, alpha=0.1
)
orbit_line
.
rotation_x
=
90
#
orbit_line.rotation_x = 90
orbit_line
.
enabled
=
False
# 默认不显示
#
orbit_line.enabled = False # 默认不显示
return
orbit_line
#
return orbit_line
def
on_ready
(
self
):
def
on_ready
(
self
):
# 运行前触发一次
# 运行前触发一次
...
@@ -83,16 +85,25 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
...
@@ -83,16 +85,25 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
application
.
time_scale
=
0.00001
application
.
time_scale
=
0.00001
# FOV是摄像机的视场角,即Field of view(FOV),它的大小决定了摄像机的视野范围。
# FOV是摄像机的视场角,即Field of view(FOV),它的大小决定了摄像机的视野范围。
camera
.
fov
=
50
camera
.
fov
=
50
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
=
create_text_panel
(
font
=
"fonts/DroidSansFallback.ttf"
,
font_scale
=
1.3
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
replace
(
"${distance}"
,
"1 AU"
).
\
replace
(
"${distance}"
,
"1 AU"
).
\
replace
(
"${velocity}"
,
"0"
).
\
replace
(
"${velocity}"
,
"0"
).
\
replace
(
"${acceleration}"
,
"0"
)
replace
(
"${acceleration}"
,
"0"
)
sky
=
create_sphere_sky
(
scale
=
10000
)
sky
.
rotation_y
=
180
# sky.rotation_x = 20
# sky.rotation_z = -65
# 创建水星轨道线
# 创建水星轨道线
self
.
mercury_orbit_line
=
create_orbit_line
(
self
.
sun
,
self
.
mercury
)
self
.
mercury_orbit_line
=
create_orbit_line
(
self
.
sun
,
self
.
mercury
,
thickness
=
3
,
alpha
=
0.3
)
# 创建金星轨道线
# 创建金星轨道线
self
.
venus_orbit_line
=
create_orbit_line
(
self
.
sun
,
self
.
venus
)
self
.
venus_orbit_line
=
create_orbit_line
(
self
.
sun
,
self
.
venus
,
thickness
=
3
,
alpha
=
0.3
)
def
show_message
(
self
,
msg
):
ControlUI
.
current_ui
.
show_message
(
msg
,
font
=
"fonts/DroidSansFallback.ttf"
,
close_time
=-
1
)
def
on_timer_changed
(
self
,
time_data
:
TimeData
):
def
on_timer_changed
(
self
,
time_data
:
TimeData
):
# 摄像机时时刻刻看向地球
# 摄像机时时刻刻看向地球
...
@@ -122,14 +133,14 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
...
@@ -122,14 +133,14 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
if
two_bodies_colliding
(
self
.
sun
,
self
.
earth
):
if
two_bodies_colliding
(
self
.
sun
,
self
.
earth
):
self
.
arrived_sun
=
True
self
.
arrived_sun
=
True
msg
=
"
地球在[%s]
到达太阳"
%
time_data
.
time_text
msg
=
"
%s
到达太阳"
%
time_data
.
time_text
print
(
msg
)
print
(
msg
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
replace
(
"${distance}"
,
"0 km"
).
\
replace
(
"${distance}"
,
"0 km"
).
\
replace
(
"${acceleration}"
,
"%s"
%
acceleration_info
).
\
replace
(
"${acceleration}"
,
"%s"
%
acceleration_info
).
\
replace
(
"${velocity}"
,
"%s km/s"
%
round
(
velocity
,
2
))
\
replace
(
"${velocity}"
,
"%s km/s"
%
round
(
velocity
,
2
))
\
+
"
\n\n
"
+
msg
+
"
\n\n
"
+
msg
ControlUI
.
current_ui
.
show_message
(
msg
,
close_time
=-
1
)
self
.
show_message
(
msg
)
application
.
pause
()
application
.
pause
()
return
return
...
@@ -185,22 +196,22 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
...
@@ -185,22 +196,22 @@ class EarthOrbitStoppedSim(UniverseSimScenes):
if
abs
(
self
.
earth
.
position
[
2
])
<
self
.
venus_radius
and
not
self
.
arrived_venus_orbit_line
:
if
abs
(
self
.
earth
.
position
[
2
])
<
self
.
venus_radius
and
not
self
.
arrived_venus_orbit_line
:
# 地球的位置小于金星轨道半径,则显示消息
# 地球的位置小于金星轨道半径,则显示消息
self
.
arrived_venus_orbit_line
=
True
# arrived_venus_orbit_line 保证只会运行一次
self
.
arrived_venus_orbit_line
=
True
# arrived_venus_orbit_line 保证只会运行一次
msg
=
"
地球在[%s]
穿过金星轨道"
%
time_data
.
time_text
msg
=
"
%s
穿过金星轨道"
%
time_data
.
time_text
print
(
msg
)
print
(
msg
)
self
.
arrived_info
=
self
.
arrived_info
+
"
\n\n
"
+
msg
self
.
arrived_info
=
self
.
arrived_info
+
"
\n\n
"
+
msg
print
(
"金星:"
,
self
.
venus
.
position
,
self
.
venus
.
velocity
)
print
(
"金星:"
,
self
.
venus
.
position
,
self
.
venus
.
velocity
)
# 显示 “地球在[某个时间]穿过金星轨道” 的消息
# 显示 “地球在[某个时间]穿过金星轨道” 的消息
ControlUI
.
current_ui
.
show_message
(
msg
,
close_time
=
5
)
self
.
show_message
(
msg
)
if
abs
(
self
.
earth
.
position
[
2
])
<
self
.
mercury_radius
and
not
self
.
arrived_mercury_orbit_line
:
if
abs
(
self
.
earth
.
position
[
2
])
<
self
.
mercury_radius
and
not
self
.
arrived_mercury_orbit_line
:
# 地球的位置小于水星轨道半径,则显示消息
# 地球的位置小于水星轨道半径,则显示消息
self
.
arrived_mercury_orbit_line
=
True
# arrived_mercury_orbit_line 保证只会运行一次
self
.
arrived_mercury_orbit_line
=
True
# arrived_mercury_orbit_line 保证只会运行一次
msg
=
"
地球在[%s]
穿过水星轨道"
%
time_data
.
time_text
msg
=
"
%s
穿过水星轨道"
%
time_data
.
time_text
print
(
msg
)
print
(
msg
)
self
.
arrived_info
=
self
.
arrived_info
+
"
\n\n
"
+
msg
self
.
arrived_info
=
self
.
arrived_info
+
"
\n\n
"
+
msg
print
(
"水星:"
,
self
.
mercury
.
position
,
self
.
mercury
.
velocity
)
print
(
"水星:"
,
self
.
mercury
.
position
,
self
.
mercury
.
velocity
)
# 显示 “地球在[某个时间]穿过水星轨道” 的消息
# 显示 “地球在[某个时间]穿过水星轨道” 的消息
ControlUI
.
current_ui
.
show_message
(
msg
,
close_time
=
5
)
self
.
show_message
(
msg
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
self
.
text_panel
.
text
=
self
.
arrived_info
.
\
replace
(
"${distance}"
,
"%s km"
%
distance_str
).
\
replace
(
"${distance}"
,
"%s km"
%
distance_str
).
\
...
@@ -243,5 +254,8 @@ if __name__ == '__main__':
...
@@ -243,5 +254,8 @@ if __name__ == '__main__':
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
# position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程
# position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程
ursina_run
(
sim
.
bodies
,
SECONDS_PER_DAY
,
position
=
(
0
,
0.0001
*
AU
,
-
0.8
*
AU
),
ursina_run
(
sim
.
bodies
,
SECONDS_PER_DAY
,
position
=
(
0
,
0.0001
*
AU
,
-
0.8
*
AU
),
show_camera_info
=
False
,
show_control_info
=
False
,
show_timer
=
True
,
show_timer
=
True
,
show_grid
=
True
)
cosmic_bg
=
''
,
show_grid
=
False
)
simulators/ursina/entities/body_timer.py
浏览文件 @
d312a416
...
@@ -47,15 +47,15 @@ class TimeData:
...
@@ -47,15 +47,15 @@ class TimeData:
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_DAYS
]:
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_DAYS
]:
self
.
time_text
=
f
'
{
self
.
years
}
年
{
s_days
}
天'
self
.
time_text
=
f
'
{
self
.
years
}
年
{
s_days
}
天'
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_MINUTES
]:
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_MINUTES
]:
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
'
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
'
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_HOURS
]:
elif
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_HOURS
]:
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
时'
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
时'
else
:
else
:
if
days
>
1
or
years
>=
1
:
if
days
>
1
or
years
>=
1
:
if
days
>=
20
or
years
>=
1
:
if
days
>=
20
or
years
>=
1
:
self
.
time_text
=
f
'
{
self
.
years
}
年
{
s_days
}
天'
self
.
time_text
=
f
'
{
self
.
years
}
年
{
s_days
}
天'
else
:
else
:
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
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
}
'
...
@@ -191,7 +191,7 @@ class BodyTimer(Singleton):
...
@@ -191,7 +191,7 @@ class BodyTimer(Singleton):
# if days >= 20 or years >= 1:
# if days >= 20 or years >= 1:
# time_text = f'{int(years)}年{s_days}天'
# time_text = f'{int(years)}年{s_days}天'
# else:
# else:
# time_text = f'{int(days)}天
{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# time_text = f'{int(days)}天{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# else:
# else:
# time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
...
...
simulators/ursina/entities/timer.py
浏览文件 @
d312a416
...
@@ -22,9 +22,19 @@ class Timer(Text):
...
@@ -22,9 +22,19 @@ class Timer(Text):
aspect_ratio
=
window
.
aspect_ratio
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.18
,
-
0.465
),
(
-
0.5
,
0.5
),
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.18
,
-
0.465
),
(
-
0.5
,
0.5
),
super
().
__init__
(
text
=
' '
,
position
=
position
,
#(0.70, -0.465),
font
=
"fonts/DroidSansFallback.ttf"
origin
=
origin
,
from
common.func
import
find_file
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
)
font
=
find_file
(
f
"
{
font
}
"
,
None
)
if
font
is
None
:
font
=
UrsinaConfig
.
CN_FONT
font_scale
=
1
else
:
font_scale
=
1.3
position
,
origin
=
(
0.5
*
aspect_ratio
-
0.15
,
-
0.465
),
(
-
0.2
,
0.2
),
super
().
__init__
(
text
=
' '
,
position
=
position
,
# (0.70, -0.465),
origin
=
origin
,
scale
=
font_scale
,
font
=
font
,
background
=
True
)
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
if
not
show
:
if
not
show
:
self
.
enabled
=
False
self
.
enabled
=
False
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录