Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
3d12df6a
宇宙模拟器
项目概览
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看板
提交
3d12df6a
编写于
4月 06, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
f4dcae33
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
46 addition
and
9 deletion
+46
-9
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+27
-3
simulators/ursina/entities/timer.py
simulators/ursina/entities/timer.py
+3
-1
simulators/ursina/ui/control_handler.py
simulators/ursina/ui/control_handler.py
+2
-2
simulators/ursina/ursina_event.py
simulators/ursina/ursina_event.py
+12
-1
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+1
-1
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+1
-1
未找到文件。
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
3d12df6a
...
...
@@ -9,6 +9,8 @@
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
,
Moon
,
Asteroids
,
Body
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_YEAR
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
if
__name__
==
'__main__'
:
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
...
...
@@ -46,12 +48,34 @@ if __name__ == '__main__':
init_velocity
=
[
0
,
0
,
299792.458
]).
set_light_disable
(
True
)
# 1 光速=299792.458 千米/秒(km/秒)
bodies
.
append
(
light_body
)
arrived_bodies
=
[]
def
on_reset
():
arrived_bodies
.
clear
()
def
on_timer_changed
(
time_text
,
time_data
):
years
,
days
,
hours
,
minutes
,
seconds
=
time_data
# UrsinaEvent.on_timer_changed(self.text, (years, days, hours, minutes, seconds))
# 光到达地球8.3分钟,
# 光到达冥王星平均用时要20000秒,333.3分钟 也就是约5.56小时
for
body
in
bodies
:
if
body
is
light_body
or
isinstance
(
body
,
Sun
)
\
or
body
in
arrived_bodies
or
isinstance
(
body
,
Asteroids
):
continue
if
light_body
.
position
[
2
]
>=
body
.
position
[
2
]:
arrived_bodies
.
append
(
body
)
print
(
f
"[
{
time_text
}
] 已经到达 [
{
body
.
name
}
]"
)
# print(light_body.planet)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
60
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
show_trail
=
True
,
show_timer
=
True
,
bg_music
=
"sounds/interstellar.mp3"
)
# 光到达地球8.3分钟,
# 光到达冥王星平均用时要20000秒,333.3分钟 也就是约5.56小时
simulators/ursina/entities/timer.py
浏览文件 @
3d12df6a
...
...
@@ -13,7 +13,7 @@ class Timer(Text):
# 用来计时的变量
# self.start_time = time.time()
self
.
reset
()
UrsinaEvent
.
on_
timer_changed
_subscription
(
self
.
update
)
UrsinaEvent
.
on_
evolving
_subscription
(
self
.
update
)
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
...
...
@@ -59,6 +59,8 @@ class Timer(Text):
else
:
self
.
text
=
f
'
{
hours
:
02
d
}
:
{
minutes
:
02
d
}
:
{
seconds
:
02
d
}
'
UrsinaEvent
.
on_timer_changed
(
self
.
text
,
(
years
,
days
,
hours
,
minutes
,
seconds
))
if
__name__
==
'__main__'
:
app
=
Ursina
()
...
...
simulators/ursina/ui/control_handler.py
浏览文件 @
3d12df6a
...
...
@@ -227,7 +227,7 @@ class ControlHandler(EventHandler):
kv
=
key
.
split
(
" "
)
self
.
shift_keys
[
kv
[
0
]]
=
False
print
(
self
.
shift_keys
)
#
print(self.shift_keys)
return
self
.
shift_keys
[
'left'
]
or
self
.
shift_keys
[
'right'
]
def
settings_handler_input
(
self
,
key
):
...
...
@@ -241,7 +241,7 @@ class ControlHandler(EventHandler):
self
.
shift_key_handle
(
key
)
self
.
camera_update
()
print
(
key
)
#
print(key)
if
key
==
"escape"
:
if
self
.
shift_keys
[
'left'
]
or
self
.
shift_keys
[
'right'
]:
sys
.
exit
()
...
...
simulators/ursina/ursina_event.py
浏览文件 @
3d12df6a
...
...
@@ -31,6 +31,8 @@ class UrsinaEvent:
UrsinaEvent
.
on_application_run_callback
=
[]
# 天体大小发生变化的订阅事件
UrsinaEvent
.
on_body_size_changed_callback
=
[]
# 逐步演变触发的订阅事件
UrsinaEvent
.
on_evolving_callback
=
[]
# 计时器触发的订阅事件
UrsinaEvent
.
on_timer_changed_callback
=
[]
...
...
@@ -48,8 +50,17 @@ class UrsinaEvent:
UrsinaEvent
.
on_timer_changed_callback
.
append
(
fun
)
@
staticmethod
def
on_timer_changed
(
evolve_dt
):
def
on_timer_changed
(
time_text
,
time_data
):
for
f
in
UrsinaEvent
.
on_timer_changed_callback
:
f
(
time_text
,
time_data
)
@
staticmethod
def
on_evolving_subscription
(
fun
):
UrsinaEvent
.
on_evolving_callback
.
append
(
fun
)
@
staticmethod
def
on_evolving
(
evolve_dt
):
for
f
in
UrsinaEvent
.
on_evolving_callback
:
f
(
evolve_dt
)
@
staticmethod
...
...
simulators/ursina_simulator.py
浏览文件 @
3d12df6a
...
...
@@ -172,7 +172,7 @@ class UrsinaSimulator(Simulator):
# 配置中,每年、月、天等等有多少秒
evolve_dt
=
UrsinaConfig
.
seconds_per
*
run_speed_factor
UrsinaEvent
.
on_
timer_changed
(
evolve_dt
)
UrsinaEvent
.
on_
evolving
(
evolve_dt
)
# interval_fator 能让更新天体运行状态(位置、速度)更精确
evolve_dt
=
evolve_dt
*
self
.
interval_fator
super
().
evolve
(
evolve_dt
)
...
...
simulators/views/ursina_view.py
浏览文件 @
3d12df6a
...
...
@@ -24,7 +24,7 @@ class UrsinaView(BodyView):
self
.
velocity
=
body
.
velocity
self
.
planet
=
Planet
(
self
)
body
.
planet
=
self
.
planet
def
update
(
self
):
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录