Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
63ff984f
宇宙模拟器
项目概览
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看板
提交
63ff984f
编写于
4月 07, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
5aa17fbc
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
124 addition
and
98 deletion
+124
-98
bodies/earth.py
bodies/earth.py
+1
-1
bodies/jupiter.py
bodies/jupiter.py
+1
-1
bodies/mars.py
bodies/mars.py
+1
-1
bodies/mercury.py
bodies/mercury.py
+1
-1
bodies/neptune.py
bodies/neptune.py
+1
-1
bodies/pluto.py
bodies/pluto.py
+1
-1
bodies/saturn.py
bodies/saturn.py
+1
-1
bodies/uranus.py
bodies/uranus.py
+1
-1
bodies/venus.py
bodies/venus.py
+1
-1
common/singleton.py
common/singleton.py
+19
-0
sim_scenes/func.py
sim_scenes/func.py
+0
-1
sim_scenes/solar_system/speed_of_light.py
sim_scenes/solar_system/speed_of_light.py
+2
-2
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+79
-0
simulators/ursina/entities/timer.py
simulators/ursina/entities/timer.py
+0
-75
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+15
-11
未找到文件。
bodies/earth.py
浏览文件 @
63ff984f
...
...
@@ -23,7 +23,7 @@ class Earth(Body):
平均密度: 5507.85 kg/m³
"""
def
__init__
(
self
,
name
=
"地球"
,
mass
=
5.97237e24
,
rotate_angle
=
0
,
init_position
=
[
0
,
0
,
1
.12
*
AU
],
init_position
=
[
0
,
0
,
1
*
AU
],
init_velocity
=
[
-
29.79
,
0
,
0
],
texture
=
"earth1.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
15
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/jupiter.py
浏览文件 @
63ff984f
...
...
@@ -23,7 +23,7 @@ class Jupiter(Body):
平均密度: 1.326 g/cm³ -> -> 1.326✕10³ kg/m³
"""
def
__init__
(
self
,
name
=
"木星"
,
mass
=
1.8982e27
,
init_position
=
[
0
,
0
,
5.
2
*
AU
],
init_position
=
[
0
,
0
,
5.
19
*
AU
],
init_velocity
=
[
-
13.06
,
0
,
0
],
texture
=
"jupiter1.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
36.2537
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/mars.py
浏览文件 @
63ff984f
...
...
@@ -23,7 +23,7 @@ class Mars(Body):
平均密度: 3.9335 g/cm³ -> 3.9335✕10³ kg/m³
"""
def
__init__
(
self
,
name
=
"火星"
,
mass
=
6.4171e23
,
init_position
=
[
0
,
0
,
1.5
*
AU
],
init_position
=
[
0
,
0
,
1.5
2
*
AU
],
init_velocity
=
[
-
24.13
,
0
,
0
],
texture
=
"mars.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
14.6223
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/mercury.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Mercury(Body):
"""
def
__init__
(
self
,
name
=
"水星"
,
mass
=
3.3011e23
,
init_position
=
[
0
,
0
,
0.4
*
AU
],
init_position
=
[
0
,
0
,
0.
38
4
*
AU
],
init_velocity
=
[
-
47.87
,
0
,
0
],
texture
=
"mercury.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
0.2558
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/neptune.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Neptune(Body):
"""
def
__init__
(
self
,
name
=
"海王星"
,
mass
=
1.0241e26
,
init_position
=
[
0
,
0
,
30
*
AU
],
init_position
=
[
0
,
0
,
30
.7
*
AU
],
init_velocity
=
[
-
5.43
,
0
,
0
],
texture
=
"neptune.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
22.3463
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/pluto.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Pluto(Body):
"""
def
__init__
(
self
,
name
=
"冥王星"
,
mass
=
1.303e22
,
init_position
=
[
0
,
0
,
40
*
AU
],
init_position
=
[
0
,
0
,
39.55
*
AU
],
init_velocity
=
[
-
4.7
,
0
,
0
],
texture
=
"pluto.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=-
2.3474
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/saturn.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Saturn(Body):
"""
def
__init__
(
self
,
name
=
"土星"
,
mass
=
5.6834e26
,
init_position
=
[
0
,
0
,
10
*
AU
],
init_position
=
[
0
,
0
,
9.5
*
AU
],
init_velocity
=
[
-
9.64
,
0
,
0
],
texture
=
"saturn.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
33.7711
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/uranus.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Uranus(Body):
"""
def
__init__
(
self
,
name
=
"天王星"
,
mass
=
8.681e25
,
init_position
=
[
0
,
0
,
19
*
AU
],
init_position
=
[
0
,
0
,
19
.2
*
AU
],
init_velocity
=
[
-
6.81
,
0
,
0
],
texture
=
"uranus.png"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=-
20.8816
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
bodies/venus.py
浏览文件 @
63ff984f
...
...
@@ -24,7 +24,7 @@ class Venus(Body):
"""
def
__init__
(
self
,
name
=
"金星"
,
mass
=
4.8675e24
,
init_position
=
[
0
,
0
,
0.72
*
AU
],
init_position
=
[
0
,
0
,
0.72
1
*
AU
],
init_velocity
=
[
-
35
,
0
,
0
],
texture
=
"venus.jpg"
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=-
0.0617
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
...
...
common/singleton.py
0 → 100644
浏览文件 @
63ff984f
# -*- coding:utf-8 -*-
# title :单例模式类
# description :单例模式类
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
class
Singleton
:
"""
单例模式类
"""
def
__new__
(
cls
,
*
args
,
**
kwargs
):
if
not
hasattr
(
cls
,
"_instance"
):
cls
.
_instance
=
super
(
Singleton
,
cls
).
__new__
(
cls
)
return
cls
.
_instance
sim_scenes/func.py
浏览文件 @
63ff984f
...
...
@@ -109,7 +109,6 @@ def ursina_run(bodies,
simulator
.
check_and_evolve
()
if
ursina_view
.
appeared
:
ursina_view
.
update
()
# print('....')
import
sys
sys
.
modules
[
"__main__"
].
update
=
callback_update
...
...
sim_scenes/solar_system/speed_of_light.py
浏览文件 @
63ff984f
...
...
@@ -20,8 +20,8 @@ arrived_info = ""
CAMERA_FOLLOW_LIGHT
=
None
# 不跟随光
#
CAMERA_FOLLOW_LIGHT = 'ForwardView' # 向前看
#
CAMERA_FOLLOW_LIGHT = 'SideView' # 侧面看
CAMERA_FOLLOW_LIGHT
=
'ForwardView'
# 向前看
CAMERA_FOLLOW_LIGHT
=
'SideView'
# 侧面看
def
on_reset
():
...
...
simulators/ursina/entities/body_timer.py
0 → 100644
浏览文件 @
63ff984f
# -*- coding:utf-8 -*-
# title :计时器天体
# description :计时器天体
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies.body
import
Body
from
common.consts
import
MO
from
common.singleton
import
Singleton
import
os
import
random
import
math
from
simulators.ursina.ursina_event
import
UrsinaEvent
class
BodyTimer
(
Singleton
):
"""
天体计时器
"""
def
__init__
(
self
):
if
not
hasattr
(
self
,
"inited"
):
self
.
velocity_inc
=
0.00001
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
self
.
inited
=
True
def
pause
(
self
):
pass
def
start
(
self
):
pass
def
reset
(
self
):
self
.
position_sum
=
0.0
def
calc_time
(
self
,
dt
):
if
not
hasattr
(
self
,
"position_sum"
):
self
.
position_sum
=
0.0
self
.
position_sum
+=
self
.
velocity_inc
*
dt
# 距离(km) / 速度(km/s) = 时间(s)
seconds
=
round
(
self
.
position_sum
/
self
.
velocity_inc
)
hours
,
remainder
=
divmod
(
seconds
,
3600
)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
days
,
hours
=
divmod
(
hours
,
24
)
years
=
days
//
365
days
=
days
%
365
if
days
>
1
:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
if
days
>=
20
or
years
>=
1
:
self
.
text
=
f
'
{
int
(
years
)
}
年
{
s_days
}
天'
else
:
self
.
text
=
f
'
{
int
(
days
)
}
天
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
else
:
self
.
text
=
f
'
{
int
(
hours
):
02
d
}
:
{
int
(
minutes
):
02
d
}
:
{
int
(
seconds
):
02
d
}
'
# print(self.text)
UrsinaEvent
.
on_timer_changed
(
self
.
text
,
(
years
,
days
,
hours
,
minutes
,
seconds
))
def
ignore_gravity
(
self
,
body
):
return
True
if
__name__
==
'__main__'
:
import
time
t
=
BodyTimer
()
print
(
id
(
t
))
print
(
id
(
BodyTimer
()))
for
i
in
range
(
1000
):
time
.
sleep
(
0.01
)
# 距离(km) = 时间(s) * 速度(km/s)
t
.
position
[
0
]
+=
300000
*
t
.
velocity_inc
t
.
calc_time
()
simulators/ursina/entities/timer.py
已删除
100644 → 0
浏览文件 @
5aa17fbc
from
ursina
import
Text
,
Ursina
,
application
import
datetime
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
class
Timer
(
Text
):
def
__init__
(
self
):
# 创建一个文本对象来显示计时器的时间
super
().
__init__
(
text
=
'00:00'
,
position
=
(
0.65
,
-
0.45
),
font
=
UrsinaConfig
.
CN_FONT
)
# 用来计时的变量
# self.start_time = time.time()
self
.
reset
()
UrsinaEvent
.
on_evolving_subscription
(
self
.
update
)
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
self
.
elapsed_time_offset
=
datetime
.
timedelta
(
microseconds
=
1
)
def
pause
(
self
):
pass
def
start
(
self
):
self
.
last_time
=
datetime
.
datetime
.
now
()
def
reset
(
self
):
self
.
last_time
=
datetime
.
datetime
.
now
()
self
.
elapsed_time
=
datetime
.
timedelta
(
0
)
def
update
(
self
,
evolve_dt
=
1
):
# # 计算当前的时间
# elapsed_time = time.time() - self.start_time
#
# # 将时间转换成“分钟:秒”的形式
# minutes = int(elapsed_time // 60)
# seconds = int(elapsed_time % 60)
# self.text = f'{minutes:02d}:{seconds:02d}'
time_scale
=
UrsinaConfig
.
get_app_time_scale
()
current_time
=
datetime
.
datetime
.
now
()
# 0.6 是对测试太阳系时间的纠正
self
.
elapsed_time
+=
(
current_time
-
self
.
last_time
)
*
evolve_dt
*
time_scale
*
0.6
# datetime.timedelta(microseconds=1) 0:00:00.000001
# datetime.timedelta(milliseconds=1) 0:00:00.001000
# self.elapsed_time += self.elapsed_time_offset # 按区域取值
self
.
last_time
=
current_time
hours
,
remainder
=
divmod
(
self
.
elapsed_time
.
seconds
,
3600
)
minutes
,
seconds
=
divmod
(
remainder
,
60
)
days
=
self
.
elapsed_time
.
days
years
=
days
//
365
days
=
days
%
365
if
days
>
1
:
s_days
=
str
(
days
).
rjust
(
3
,
" "
)
if
days
>=
20
or
years
>=
1
:
self
.
text
=
f
'
{
years
}
年
{
s_days
}
天'
else
:
self
.
text
=
f
'
{
days
}
天
{
hours
:
02
d
}
:
{
minutes
:
02
d
}
:
{
seconds
:
02
d
}
'
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
()
t
=
Timer
()
def
update
():
t
.
update
()
app
.
run
()
simulators/ursina_simulator.py
浏览文件 @
63ff984f
...
...
@@ -14,7 +14,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ui.control_handler
import
ControlHandler
from
simulators.ursina.ursina_mesh
import
create_arrow_line
from
simulators.ursina.entities.body_timer
import
BodyTimer
from
simulators.views.ursina_view
import
UrsinaView
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.simulator
import
Simulator
...
...
@@ -177,12 +177,16 @@ class UrsinaSimulator(Simulator):
evolve_dt
=
evolve_dt
*
self
.
interval_fator
super
().
evolve
(
evolve_dt
)
if
self
.
show_timer
:
timer
=
BodyTimer
()
timer
.
calc_time
(
evolve_dt
)
def
create_timer
(
self
):
from
simulators.ursina.entities.timer
import
Timer
# 创建一个文本对象来显示计时器的时间
self
.
timer
=
Timer
()
return
self
.
timer
#
def create_timer(self):
#
from simulators.ursina.entities.timer import Timer
#
# 创建一个文本对象来显示计时器的时间
#
self.timer = Timer()
#
return self.timer
def
cosmic_background
(
self
,
texture
=
'../textures/cosmic2.jpg'
):
"""
...
...
@@ -222,9 +226,9 @@ class UrsinaSimulator(Simulator):
if
"view_closely"
in
kwargs
:
view_closely
=
kwargs
[
"view_closely"
]
show_timer
=
False
s
elf
.
s
how_timer
=
False
if
"show_timer"
in
kwargs
:
show_timer
=
kwargs
[
"show_timer"
]
s
elf
.
s
how_timer
=
kwargs
[
"show_timer"
]
if
view_closely
:
# 近距离查看
...
...
@@ -278,8 +282,8 @@ class UrsinaSimulator(Simulator):
# ui = UrsinaUI()
ctl
=
ControlUI
(
ControlHandler
(),
position
=
(
0.6
,
0.5
))
if
show_timer
:
self
.
create_timer
()
#
if show_timer:
#
self.create_timer()
EditorCamera
(
ignore_paused
=
True
)
# 防止打开中文输入法
...
...
@@ -308,7 +312,7 @@ class UrsinaSimulator(Simulator):
audio
=
Audio
(
bg_music
,
pitch
=
1
,
loop
=
True
,
autoplay
=
True
)
audio
.
volume
=
0.3
if
show_timer
:
if
s
elf
.
s
how_timer
:
UrsinaEvent
.
on_reset
()
UrsinaEvent
.
on_ready
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录