Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
d5751b76
宇宙模拟器
项目概览
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看板
提交
d5751b76
编写于
4月 08, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
74359545
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
28 deletion
+65
-28
sim_scenes/solar_system/speed_of_light_init.py
sim_scenes/solar_system/speed_of_light_init.py
+19
-9
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+41
-15
simulators/ursina/entities/timer.py
simulators/ursina/entities/timer.py
+3
-2
simulators/ursina/ursina_event.py
simulators/ursina/ursina_event.py
+2
-2
未找到文件。
sim_scenes/solar_system/speed_of_light_init.py
浏览文件 @
d5751b76
...
@@ -9,8 +9,10 @@
...
@@ -9,8 +9,10 @@
from
bodies
import
Sun
,
Asteroids
,
Body
from
bodies
import
Sun
,
Asteroids
,
Body
from
common.consts
import
AU
from
common.consts
import
AU
from
sim_scenes.func
import
create_text_panel
from
sim_scenes.func
import
create_text_panel
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
from
ursina
import
camera
import
datetime
class
SpeedOfLightInit
:
class
SpeedOfLightInit
:
...
@@ -73,9 +75,9 @@ class SpeedOfLightInit:
...
@@ -73,9 +75,9 @@ class SpeedOfLightInit:
@return:
@return:
"""
"""
self
.
arrived_bodies
.
clear
()
# 重置存放记录光体已到达天体列表
self
.
arrived_bodies
.
clear
()
# 重置存放记录光体已到达天体列表
self
.
arrived_info
=
"
[00:00:00]
\t
从 [太阳] 出发
\n\n
"
self
.
arrived_info
=
"
距离[太阳]:${distance}
\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
.
replace
(
"${distance}"
,
"0 AU"
)
def
event_subscription
(
self
):
def
event_subscription
(
self
):
"""
"""
...
@@ -118,7 +120,7 @@ class SpeedOfLightInit:
...
@@ -118,7 +120,7 @@ class SpeedOfLightInit:
@return:
@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
.
replace
(
"${distance}"
,
"0 AU"
)
if
self
.
__camera_follow_light
==
"SideView"
:
if
self
.
__camera_follow_light
==
"SideView"
:
camera
.
parent
=
self
.
light_body
.
planet
camera
.
parent
=
self
.
light_body
.
planet
...
@@ -129,14 +131,12 @@ class SpeedOfLightInit:
...
@@ -129,14 +131,12 @@ class SpeedOfLightInit:
self
.
light_body
.
planet
.
input
=
self
.
light_body_input
self
.
light_body
.
planet
.
input
=
self
.
light_body_input
camera
.
rotation_y
=
-
15
camera
.
rotation_y
=
-
15
def
on_timer_changed
(
self
,
time_
text
,
time_d
ata
):
def
on_timer_changed
(
self
,
time_
data
:
TimeD
ata
):
"""
"""
计时器触发
计时器触发
@param time_text: 计时器时间文本
@param time_data: 计时器时间数据
@param time_data: 计时器时间数据
@return:
@return:
"""
"""
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
)
\
or
body
in
self
.
arrived_bodies
or
isinstance
(
body
,
Asteroids
):
or
body
in
self
.
arrived_bodies
or
isinstance
(
body
,
Asteroids
):
...
@@ -146,6 +146,16 @@ class SpeedOfLightInit:
...
@@ -146,6 +146,16 @@ class SpeedOfLightInit:
if
self
.
light_body
.
position
[
2
]
>=
body
.
position
[
2
]:
if
self
.
light_body
.
position
[
2
]
>=
body
.
position
[
2
]:
self
.
arrived_bodies
.
append
(
body
)
self
.
arrived_bodies
.
append
(
body
)
if
self
.
text_panel
is
not
None
:
if
self
.
text_panel
is
not
None
:
self
.
arrived_info
+=
f
"[
{
time_text
}
]
\t
到达
\t
[
{
body
.
name
}
]
\n\n
"
self
.
arrived_info
+=
f
"[
{
time_data
.
time_text
}
]
\t
到达
\t
[
{
body
.
name
}
]
\n\n
"
self
.
text_panel
.
text
=
self
.
arrived_info
distance
=
round
(
self
.
light_body
.
position
[
2
]
/
AU
,
2
)
print
(
f
"[
{
time_text
}
] 到达 [
{
body
.
name
}
]"
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
f
"
{
distance
}
AU"
)
print
(
f
"[
{
time_data
.
time_text
}
] 到达 [
{
body
.
name
}
]"
)
return
if
not
hasattr
(
self
,
"last_time"
):
self
.
last_time
=
datetime
.
datetime
.
now
()
else
:
if
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
milliseconds
=
1000
)
>
self
.
last_time
:
distance
=
round
(
self
.
light_body
.
position
[
2
]
/
AU
,
2
)
self
.
text_panel
.
text
=
self
.
arrived_info
.
replace
(
"${distance}"
,
f
"
{
distance
}
AU"
)
self
.
last_time
=
datetime
.
datetime
.
now
()
simulators/ursina/entities/body_timer.py
浏览文件 @
d5751b76
...
@@ -16,6 +16,32 @@ import math
...
@@ -16,6 +16,32 @@ import math
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
class
TimeData
:
def
__init__
(
self
,
seconds
):
self
.
total_seconds
=
seconds
# 获取到 seconds 后,通过下面的计算得到时分秒、年、天
hours
,
remainder
=
divmod
(
seconds
,
3600
)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
days
,
hours
=
divmod
(
hours
,
24
)
years
=
days
//
365
days
=
days
%
365
self
.
years
=
int
(
years
)
self
.
days
=
int
(
days
)
self
.
hours
=
int
(
hours
)
self
.
minutes
=
int
(
minutes
)
self
.
seconds
=
int
(
seconds
)
if
days
>
1
:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
if
days
>=
20
or
years
>=
1
:
self
.
time_text
=
f
'
{
self
.
years
}
年
{
s_days
}
天'
else
:
self
.
time_text
=
f
'
{
self
.
days
}
天
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
else
:
self
.
time_text
=
f
'
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
class
BodyTimer
(
Singleton
):
class
BodyTimer
(
Singleton
):
"""
"""
天体计时器,原理就是:
天体计时器,原理就是:
...
@@ -51,23 +77,23 @@ class BodyTimer(Singleton):
...
@@ -51,23 +77,23 @@ class BodyTimer(Singleton):
# 距离(km) / 速度(km/s) = 时间(s)
# 距离(km) / 速度(km/s) = 时间(s)
seconds
=
round
(
self
.
position_sum
/
self
.
velocity_inc
)
seconds
=
round
(
self
.
position_sum
/
self
.
velocity_inc
)
# 获取到 seconds 后,通过下面的计算得到时分秒、年、天
#
#
获取到 seconds 后,通过下面的计算得到时分秒、年、天
hours
,
remainder
=
divmod
(
seconds
,
3600
)
#
hours, remainder = divmod(seconds, 3600)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
#
minutes, seconds = divmod(remainder, 60)
days
,
hours
=
divmod
(
hours
,
24
)
#
days, hours = divmod(hours, 24)
years
=
days
//
365
#
years = days // 365
days
=
days
%
365
#
days = days % 365
if
days
>
1
:
#
if days > 1:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
#
s_days = str(days).rjust(3, " ")
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
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
#
time_text = f'{int(days)}天 {int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
else
:
#
else:
time_text
=
f
'
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
#
time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# print(self.text)
# print(self.text)
UrsinaEvent
.
on_timer_changed
(
time_text
,
(
years
,
days
,
hours
,
minutes
,
seconds
))
UrsinaEvent
.
on_timer_changed
(
TimeData
(
seconds
))
def
ignore_gravity
(
self
,
body
):
def
ignore_gravity
(
self
,
body
):
return
True
return
True
...
...
simulators/ursina/entities/timer.py
浏览文件 @
d5751b76
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
from
ursina
import
Text
,
Ursina
,
application
from
ursina
import
Text
,
Ursina
,
application
import
datetime
import
datetime
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
...
@@ -22,8 +23,8 @@ class Timer(Text):
...
@@ -22,8 +23,8 @@ class Timer(Text):
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
)
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_d
ata
):
def
on_timer_changed
(
self
,
time_
data
:
TimeD
ata
):
self
.
text
=
time_text
self
.
text
=
time_
data
.
time_
text
def
update
(
self
):
def
update
(
self
):
self
.
text
=
"00:00:00"
self
.
text
=
"00:00:00"
...
...
simulators/ursina/ursina_event.py
浏览文件 @
d5751b76
...
@@ -52,9 +52,9 @@ class UrsinaEvent:
...
@@ -52,9 +52,9 @@ class UrsinaEvent:
UrsinaEvent
.
on_timer_changed_callback
.
append
(
fun
)
UrsinaEvent
.
on_timer_changed_callback
.
append
(
fun
)
@
staticmethod
@
staticmethod
def
on_timer_changed
(
time_
text
,
time_
data
):
def
on_timer_changed
(
time_data
):
for
f
in
UrsinaEvent
.
on_timer_changed_callback
:
for
f
in
UrsinaEvent
.
on_timer_changed_callback
:
f
(
time_
text
,
time_
data
)
f
(
time_data
)
@
staticmethod
@
staticmethod
def
on_evolving_subscription
(
fun
):
def
on_evolving_subscription
(
fun
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录