Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
cd63d814
宇宙模拟器
项目概览
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看板
提交
cd63d814
编写于
6月 10, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
d4f4c749
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
21 addition
and
14 deletion
+21
-14
sim_scenes/science/earth_seasons.py
sim_scenes/science/earth_seasons.py
+2
-2
sim_scenes/science/lagrangian_points_2.py
sim_scenes/science/lagrangian_points_2.py
+8
-7
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+11
-5
未找到文件。
sim_scenes/science/earth_seasons.py
浏览文件 @
cd63d814
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
from
bodies
import
Sun
,
Earth
from
bodies
import
Sun
,
Earth
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
AU
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
AU
from
sim_scenes.func
import
ursina_run
,
camera_look_at
from
sim_scenes.func
import
ursina_run
,
camera_look_at
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.body_timer
import
TimeData
,
BodyTimer
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
from
ursina
import
camera
...
@@ -101,7 +101,7 @@ if __name__ == '__main__':
...
@@ -101,7 +101,7 @@ if __name__ == '__main__':
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
BodyTimer
().
min_unit
=
BodyTimer
.
MIN_UNIT_DAYS
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
...
...
sim_scenes/science/lagrangian_points_2.py
浏览文件 @
cd63d814
...
@@ -73,6 +73,7 @@ if __name__ == '__main__':
...
@@ -73,6 +73,7 @@ if __name__ == '__main__':
if
hasattr
(
earth
,
"lines"
):
if
hasattr
(
earth
,
"lines"
):
for
line
in
earth
.
lines
:
for
line
in
earth
.
lines
:
destroy
(
line
)
destroy
(
line
)
if
int
(
time_data
.
total_hours
)
%
3
==
0
:
# 创建连接线(将卫星列表用线条连接起来)
# 创建连接线(将卫星列表用线条连接起来)
earth
.
lines
=
create_connecting_lines
([
earth
.
lines
=
create_connecting_lines
([
[
satelliteL2
,
satelliteL3
],
[
satelliteL2
,
satelliteL3
],
...
...
simulators/ursina/entities/body_timer.py
浏览文件 @
cd63d814
...
@@ -17,7 +17,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
...
@@ -17,7 +17,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
class
TimeData
:
class
TimeData
:
def
__init__
(
self
,
seconds
):
def
__init__
(
self
,
seconds
,
min_unit
):
self
.
total_seconds
=
seconds
self
.
total_seconds
=
seconds
# 获取到 seconds 后,通过下面的计算得到时分秒、年、天
# 获取到 seconds 后,通过下面的计算得到时分秒、年、天
hours
,
remainder
=
divmod
(
seconds
,
3600
)
hours
,
remainder
=
divmod
(
seconds
,
3600
)
...
@@ -31,10 +31,13 @@ class TimeData:
...
@@ -31,10 +31,13 @@ class TimeData:
self
.
hours
=
int
(
hours
)
self
.
hours
=
int
(
hours
)
self
.
minutes
=
int
(
minutes
)
self
.
minutes
=
int
(
minutes
)
self
.
seconds
=
int
(
seconds
)
self
.
seconds
=
int
(
seconds
)
self
.
min_unit
=
min_unit
if
days
>
1
:
if
days
>
1
or
years
>=
1
or
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_DAYS
,
BodyTimer
.
MIN_UNIT_YEARS
]
:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
if
days
>=
20
or
years
>=
1
:
if
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_YEARS
]:
self
.
time_text
=
f
'
{
self
.
years
}
年'
elif
days
>=
20
or
years
>=
1
or
self
.
min_unit
in
[
BodyTimer
.
MIN_UNIT_DAYS
]:
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
}
'
...
@@ -49,7 +52,6 @@ class TimeData:
...
@@ -49,7 +52,6 @@ class TimeData:
def
total_hours
(
self
):
def
total_hours
(
self
):
return
self
.
total_seconds
/
3600
return
self
.
total_seconds
/
3600
@
property
@
property
def
total_days
(
self
):
def
total_days
(
self
):
return
self
.
total_hours
/
24
return
self
.
total_hours
/
24
...
@@ -62,6 +64,9 @@ class BodyTimer(Singleton):
...
@@ -62,6 +64,9 @@ class BodyTimer(Singleton):
通过公式: 速度 * 时间 = 距离,获取到累计距离, self.position_sum += self.velocity_inc * dt
通过公式: 速度 * 时间 = 距离,获取到累计距离, self.position_sum += self.velocity_inc * dt
最后通过公式: 时间 = 距离 / 速度, 从而得到天体运行了多长时间
最后通过公式: 时间 = 距离 / 速度, 从而得到天体运行了多长时间
"""
"""
MIN_UNIT_SECONDS
=
"seconds"
MIN_UNIT_DAYS
=
"days"
MIN_UNIT_YEARS
=
"years"
def
__init__
(
self
):
def
__init__
(
self
):
if
not
hasattr
(
self
,
"inited"
):
if
not
hasattr
(
self
,
"inited"
):
...
@@ -71,6 +76,7 @@ class BodyTimer(Singleton):
...
@@ -71,6 +76,7 @@ class BodyTimer(Singleton):
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
self
.
inited
=
True
self
.
inited
=
True
self
.
min_unit
=
BodyTimer
.
MIN_UNIT_SECONDS
def
pause
(
self
):
def
pause
(
self
):
pass
pass
...
@@ -107,7 +113,7 @@ class BodyTimer(Singleton):
...
@@ -107,7 +113,7 @@ class BodyTimer(Singleton):
# time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# time_text = f'{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}'
# print(self.text)
# print(self.text)
UrsinaEvent
.
on_timer_changed
(
TimeData
(
seconds
))
UrsinaEvent
.
on_timer_changed
(
TimeData
(
seconds
,
self
.
min_unit
))
def
ignore_gravity
(
self
,
body
):
def
ignore_gravity
(
self
,
body
):
return
True
return
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录