Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
0fe675f0
宇宙模拟器
项目概览
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看板
提交
0fe675f0
编写于
4月 08, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
abd6ec68
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
39 addition
and
11 deletion
+39
-11
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+4
-3
sim_scenes/solar_system/speed_of_light_init.py
sim_scenes/solar_system/speed_of_light_init.py
+29
-7
simulators/ursina/entities/timer.py
simulators/ursina/entities/timer.py
+6
-1
未找到文件。
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
0fe675f0
...
@@ -12,7 +12,7 @@ from sim_scenes.solar_system.speed_of_light_init import SpeedOfLightInit
...
@@ -12,7 +12,7 @@ from sim_scenes.solar_system.speed_of_light_init import SpeedOfLightInit
camera_follow_light
=
None
# 摄像机固定,不会跟随光
camera_follow_light
=
None
# 摄像机固定,不会跟随光
camera_follow_light
=
'ForwardView'
# 摄像机跟随光,方向是向前看
camera_follow_light
=
'ForwardView'
# 摄像机跟随光,方向是向前看
camera_follow_light
=
'SideView'
# 摄像机跟随光,方向是侧面看
#
camera_follow_light = 'SideView' # 摄像机跟随光,方向是侧面看
# 实例化一个初始化对象(订阅事件,记录到达每个行星所需要的时间)
# 实例化一个初始化对象(订阅事件,记录到达每个行星所需要的时间)
init
=
SpeedOfLightInit
(
camera_follow_light
)
init
=
SpeedOfLightInit
(
camera_follow_light
)
...
@@ -34,7 +34,8 @@ init.event_subscription()
...
@@ -34,7 +34,8 @@ init.event_subscription()
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
60
,
ursina_run
(
bodies
,
60
,
position
=
init
.
position
,
position
=
init
.
camera_position
,
show_trail
=
init
.
show_trail
,
show_timer
=
True
,
show_trail
=
init
.
show_trail
,
show_timer
=
True
,
# view_closely=True,
# view_closely=True,
bg_music
=
"sounds/interstellar.mp3"
)
bg_music
=
"sounds/interstellar.mp3"
)
sim_scenes/solar_system/speed_of_light_init.py
浏览文件 @
0fe675f0
...
@@ -34,31 +34,44 @@ class SpeedOfLightInit:
...
@@ -34,31 +34,44 @@ class SpeedOfLightInit:
if
self
.
__camera_follow_light
==
"SideView"
:
if
self
.
__camera_follow_light
==
"SideView"
:
# 摄像机位置 = 前-后+、上+下-、左-右+、
# 摄像机位置 = 前-后+、上+下-、左-右+、
self
.
position
=
(
AU
,
0
,
0
)
self
.
camera_
position
=
(
AU
,
0
,
0
)
self
.
show_trail
=
True
self
.
show_trail
=
True
self
.
light_size_scale
=
1e3
self
.
light_size_scale
=
1e3
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
elif
self
.
__camera_follow_light
==
"ForwardView"
:
elif
self
.
__camera_follow_light
==
"ForwardView"
:
# 摄像机位置 = 左-右+、上+下-、前+后-
# 摄像机位置 = 左-右+、上+下-、前+后-
self
.
position
=
(
0
,
AU
/
10
,
-
AU
)
self
.
camera_
position
=
(
0
,
AU
/
10
,
-
AU
)
self
.
show_trail
=
Fals
e
self
.
show_trail
=
Tru
e
self
.
light_size_scale
=
1e2
self
.
light_size_scale
=
1e2
self
.
light_init_position
=
[
AU
/
12
,
0
,
0
]
self
.
light_init_position
=
[
AU
/
12
,
0
,
0
]
else
:
else
:
# 摄像机位置 = 左-右+、上+下-、前+后-
# 摄像机位置 = 左-右+、上+下-、前+后-
self
.
position
=
(
0
,
AU
,
-
6
*
AU
)
self
.
camera_
position
=
(
0
,
AU
,
-
6
*
AU
)
self
.
show_trail
=
True
self
.
show_trail
=
True
self
.
light_size_scale
=
2e3
self
.
light_size_scale
=
2e3
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
self
.
light_init_position
=
[
AU
/
3
,
0
,
0
]
# 点击了重置按钮
def
on_reset
(
self
):
def
on_reset
(
self
):
"""
点击了重置按钮触发
@return:
"""
self
.
arrived_bodies
.
clear
()
# 重置存放记录光体已到达天体列表
self
.
arrived_bodies
.
clear
()
# 重置存放记录光体已到达天体列表
self
.
arrived_info
=
"[00:00:00]
\t
从 [太阳] 出发
\n\n
"
self
.
arrived_info
=
"[00:00:00]
\t
从 [太阳] 出发
\n\n
"
if
self
.
text_panel
is
not
None
:
if
self
.
text_panel
is
not
None
:
self
.
text_panel
.
text
=
self
.
arrived_info
self
.
text_panel
.
text
=
self
.
arrived_info
def
event_subscription
(
self
):
def
event_subscription
(
self
):
"""
订阅事件
@return:
"""
if
self
.
light_body
is
None
:
raise
Exception
(
"请指定 SpeedOfLightInit.light_body"
)
if
self
.
bodies
is
None
:
raise
Exception
(
"请指定 SpeedOfLightInit.bodies"
)
# 订阅重新开始事件
# 订阅重新开始事件
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
UrsinaEvent
.
on_ready_subscription
(
self
.
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
self
.
on_ready
)
...
@@ -66,6 +79,10 @@ class SpeedOfLightInit:
...
@@ -66,6 +79,10 @@ class SpeedOfLightInit:
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
def
on_ready
(
self
):
def
on_ready
(
self
):
"""
模拟器开始运行前触发
@return:
"""
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
=
create_text_panel
()
self
.
text_panel
.
text
=
self
.
arrived_info
self
.
text_panel
.
text
=
self
.
arrived_info
...
@@ -73,12 +90,17 @@ class SpeedOfLightInit:
...
@@ -73,12 +90,17 @@ class SpeedOfLightInit:
camera
.
parent
=
self
.
light_body
.
planet
camera
.
parent
=
self
.
light_body
.
planet
camera
.
rotation_y
=
-
85
camera
.
rotation_y
=
-
85
elif
self
.
__camera_follow_light
==
"ForwardView"
:
elif
self
.
__camera_follow_light
==
"ForwardView"
:
self
.
light_body
.
planet
.
enabled
=
False
#
self.light_body.planet.enabled = False
camera
.
parent
=
self
.
light_body
.
planet
camera
.
parent
=
self
.
light_body
.
planet
camera
.
rotation_y
=
-
15
camera
.
rotation_y
=
-
15
def
on_timer_changed
(
self
,
time_text
,
time_data
):
def
on_timer_changed
(
self
,
time_text
,
time_data
):
global
arrived_info
"""
计时器触发
@param time_text: 计时器时间文本
@param time_data: 计时器时间数据
@return:
"""
years
,
days
,
hours
,
minutes
,
seconds
=
time_data
years
,
days
,
hours
,
minutes
,
seconds
=
time_data
for
body
in
self
.
bodies
:
for
body
in
self
.
bodies
:
if
body
is
self
.
light_body
or
isinstance
(
body
,
Sun
)
\
if
body
is
self
.
light_body
or
isinstance
(
body
,
Sun
)
\
...
...
simulators/ursina/entities/timer.py
浏览文件 @
0fe675f0
...
@@ -17,12 +17,17 @@ class Timer(Text):
...
@@ -17,12 +17,17 @@ class Timer(Text):
def
__init__
(
self
):
def
__init__
(
self
):
# 创建一个文本对象来显示计时器的时间
# 创建一个文本对象来显示计时器的时间
super
().
__init__
(
text
=
'00:00'
,
position
=
(
0.65
,
-
0.45
),
font
=
UrsinaConfig
.
CN_FONT
)
super
().
__init__
(
text
=
' '
,
position
=
(
0.70
,
-
0.465
),
origin
=
(
-
0.5
,
0.5
),
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
)
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
def
on_timer_changed
(
self
,
time_text
,
time_data
):
def
on_timer_changed
(
self
,
time_text
,
time_data
):
self
.
text
=
time_text
self
.
text
=
time_text
def
update
(
self
):
self
.
text
=
"00:00:00"
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
=
Ursina
()
app
=
Ursina
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录