Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
6a718659
宇宙模拟器
项目概览
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看板
提交
6a718659
编写于
7月 23, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
e2269f18
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
138 addition
and
7 deletion
+138
-7
sim_scenes/func.py
sim_scenes/func.py
+3
-1
sim_scenes/solar_system/solar_system_reality.py
sim_scenes/solar_system/solar_system_reality.py
+109
-0
simulators/simulator.py
simulators/simulator.py
+6
-2
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+11
-0
simulators/ursina/ui/ui_panel.py
simulators/ursina/ui/ui_panel.py
+7
-2
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+2
-2
未找到文件。
sim_scenes/func.py
浏览文件 @
6a718659
...
...
@@ -117,6 +117,7 @@ def ursina_run(bodies,
show_exit_button
=
True
,
grid_position
=
None
,
grid_scale
=
None
,
gravity_works
=
True
,
show_trail
=
False
,
show_name
=
False
,
show_timer
=
False
,
...
...
@@ -135,6 +136,7 @@ def ursina_run(bodies,
@param show_camera_info: 是否显示摄像机信息面板
@param show_control_info: 是否显示控制信息面板
@param show_exit_button: 是否显示模拟器关闭按钮
@param gravity_works: 万有引力是否启用
@param show_trail: 是否显示拖尾
@param show_name: 是否显示天体名称
@param show_timer: 是否显示计时器
...
...
@@ -171,7 +173,7 @@ def ursina_run(bodies,
def
callback_update
():
UrsinaEvent
.
on_application_run
()
for
ursina_view
in
simulator
.
ursina_views
:
simulator
.
check_and_evolve
()
simulator
.
check_and_evolve
(
gravity_works
)
if
ursina_view
.
appeared
:
ursina_view
.
update
()
...
...
sim_scenes/solar_system/solar_system_reality.py
0 → 100644
浏览文件 @
6a718659
# -*- coding:utf-8 -*-
# title :模拟太阳系给天体真实时间和位置
# description :模拟太阳系给天体真实时间和位置
# author :Python超人
# date :2023-07-23
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
import
numpy
as
np
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
,
Moon
,
Asteroids
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.entities.body_timer
import
TimeData
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
astropy.coordinates
import
get_body_barycentric
from
astropy.time
import
Time
def
get_bodies_positions
(
planet_names
=
"sun,mercury,venus,earth,moon,mars,jupiter,saturn,uranus,neptune"
,
time
=
None
):
if
time
is
None
:
time
=
Time
.
now
()
planets
=
planet_names
.
split
(
","
)
positions
=
{}
for
planet
in
planets
:
try
:
position
=
get_body_barycentric
(
planet
,
time
)
positions
[
planet
]
=
position
print
(
planet
,
position
)
except
Exception
as
e
:
print
(
planet
,
str
(
e
))
return
positions
def
get_bodies_names
(
bodies
):
names
=
""
for
body
in
bodies
:
names
+=
body
.
__class__
.
__name__
+
","
return
names
[
0
:
-
1
]
current_time
=
Time
.
now
()
if
__name__
==
'__main__'
:
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
# 排列顺序
# 1、体积:(以地球为1)木星 :土星 :天王星 :海王星 :地球 :金星 :火星 :水星 = 1330:745:65:60:1:0.86:0.15:0.056
# 2、质量:(以地球为1)木星 :土星 :天王星 :海王星 :地球 :金星 :火星 :水星 = 318:95:14.53:17.15:1:0.8:0.11:0.0553
# 3、离太阳从近到远的顺序:水星、金星、地球、火星、木星、土星、天王星、海王星
# =====================================================================
# 以下展示的效果为太阳系真实的距离
# 由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大
sun
=
Sun
(
name
=
"太阳"
,
size_scale
=
0.4e2
)
# 太阳放大 80 倍,距离保持不变
bodies
=
[
sun
,
Mercury
(
name
=
"水星"
,
size_scale
=
3e3
),
# 水星
Venus
(
name
=
"金星"
,
size_scale
=
3e3
),
# 金星
Earth
(
name
=
"地球"
,
size_scale
=
3e3
),
# 地球
Moon
(
name
=
"月球"
,
size_scale
=
3e3
),
# 月球
Mars
(
name
=
"火星"
,
size_scale
=
3e3
),
# 火星
Jupiter
(
name
=
"木星"
,
size_scale
=
6e2
),
# 木星
Saturn
(
name
=
"土星"
,
size_scale
=
6e2
),
# 土星
Uranus
(
name
=
"天王星"
,
size_scale
=
10e2
),
# 天王星
Neptune
(
name
=
"海王星"
,
size_scale
=
10e2
),
# 海王星
]
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com de423
names
=
get_bodies_names
(
bodies
)
def
get_body_position
(
body
,
positions
):
position
=
positions
.
get
(
body
.
__class__
.
__name__
,
None
)
if
position
is
None
:
return
[
0
,
0
,
0
]
# return [position.x.value * AU, position.y.value * AU, position.z.value * AU]
return
[
position
.
x
.
value
*
AU
,
position
.
z
.
value
*
AU
,
position
.
y
.
value
*
AU
]
def
on_ready
():
# 运行前触发
pass
def
on_timer_changed
(
time_data
:
TimeData
):
t
=
current_time
+
time_data
.
total_days
positions
=
get_bodies_positions
(
names
,
t
)
for
body
in
bodies
:
position
=
get_body_position
(
body
,
positions
)
body
.
position
=
np
.
array
(
position
)
dt
=
time_data
.
get_datetime
(
str
(
current_time
))
# print(time_data.get_datetime(str(current_time)))
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d %H:%M:%S'
),
font
=
"simsun.ttc"
,
close_time
=-
1
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_WEEK
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
gravity_works
=
False
,
# 关闭万有引力的计算
show_grid
=
False
,
show_timer
=
True
)
simulators/simulator.py
浏览文件 @
6a718659
...
...
@@ -35,13 +35,17 @@ class Simulator(metaclass=ABCMeta):
view
=
viewer_type
(
body
,
self
.
bodies_sys
)
self
.
body_views
.
append
(
view
)
def
evolve
(
self
,
dt
:
int
):
def
evolve
(
self
,
dt
:
int
,
gravity_works
=
True
):
"""
单位:秒,按时间差进行演变,值越小越精确,但演变速度会慢。
@param dt: 时间差(秒)
@param gravity_works: 万有引力是否起作用
@return:
"""
if
gravity_works
:
self
.
bodies_sys
.
evolve
(
dt
)
for
idx
,
view
in
enumerate
(
self
.
body_views
):
body
=
self
.
bodies_sys
.
bodies
[
idx
]
body
.
dt
=
dt
...
...
simulators/ursina/entities/body_timer.py
浏览文件 @
6a718659
...
...
@@ -59,6 +59,17 @@ class TimeData:
else
:
self
.
time_text
=
f
'
{
self
.
hours
:
02
d
}
:
{
self
.
minutes
:
02
d
}
:
{
self
.
seconds
:
02
d
}
'
def
get_datetime
(
self
,
init_datetime
):
import
datetime
# UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ"
UTC
=
datetime
.
datetime
.
strptime
(
init_datetime
+
"Z"
,
"%Y-%m-%d %H:%M:%S.%fZ"
)
# BJS_format = "%Y-%m-%d %H:%M:%S"
BJS
=
UTC
+
datetime
.
timedelta
(
hours
=
8
+
self
.
total_hours
)
# BJS = BJS.strftime(BJS_format)
# dt = datetime(init_datetime)
return
BJS
@
property
def
total_minutes
(
self
):
return
self
.
total_seconds
/
60
...
...
simulators/ursina/ui/ui_panel.py
浏览文件 @
6a718659
...
...
@@ -63,17 +63,22 @@ class UiPanel(WindowPanel):
"""
pass
def
show_message
(
self
,
message
,
close_time
=
3
):
def
show_message
(
self
,
message
,
font
=
None
,
close_time
=
3
):
"""
显示消息框
@param message: 消息内容
@param font: 字体
@param close_time: 定义显示消息框关闭时间
@return:
"""
if
hasattr
(
self
,
"last_message_box"
):
destroy
(
self
.
last_message_box
)
if
font
is
None
:
font
=
UrsinaConfig
.
CN_FONT
# else:
# font = None
# 创建消息框
message_box
=
Text
(
text
=
message
,
font
=
UrsinaConfig
.
CN_FONT
,
background
=
True
,
origin
=
(
0
,
0
),
y
=
.
25
)
message_box
=
Text
(
text
=
message
,
font
=
font
,
background
=
True
,
origin
=
(
0
,
0
),
y
=
.
25
)
self
.
last_message_box
=
message_box
...
...
simulators/ursina_simulator.py
浏览文件 @
6a718659
...
...
@@ -210,7 +210,7 @@ class UrsinaSimulator(Simulator):
self
.
last_time
=
now
return
is_expired
def
check_and_evolve
(
self
):
def
check_and_evolve
(
self
,
gravity_works
=
True
):
if
self
.
check_interval_expired
():
# 获取配置中的运行速度的因子
run_speed_factor
=
float
(
UrsinaConfig
.
run_speed_factor
)
...
...
@@ -227,7 +227,7 @@ class UrsinaSimulator(Simulator):
evolve_args
=
{
"evolve_dt"
:
evolve_dt
}
UrsinaEvent
.
on_before_evolving
(
evolve_args
)
# if evolve_args["evolve_dt"] > 0:
super
().
evolve
(
evolve_args
[
"evolve_dt"
])
super
().
evolve
(
evolve_args
[
"evolve_dt"
]
,
gravity_works
=
gravity_works
)
if
self
.
show_timer
or
self
.
timer_enabled
:
timer
=
BodyTimer
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录