Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
ac4f1531
宇宙模拟器
项目概览
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看板
提交
ac4f1531
编写于
4月 22, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
836d4ba9
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
69 addition
and
33 deletion
+69
-33
sim_lab/earth_moon.py
sim_lab/earth_moon.py
+3
-0
sim_lab/lagrangian_points.py
sim_lab/lagrangian_points.py
+0
-0
sim_scenes/earth/earth_satellites.py
sim_scenes/earth/earth_satellites.py
+3
-0
sim_scenes/funny/dancing_with_jupiter.py
sim_scenes/funny/dancing_with_jupiter.py
+3
-0
sim_scenes/science/earth_seasons.py
sim_scenes/science/earth_seasons.py
+3
-0
sim_scenes/science/parabolic_curve.py
sim_scenes/science/parabolic_curve.py
+30
-25
sim_scenes/science/speed_of_light_init.py
sim_scenes/science/speed_of_light_init.py
+4
-1
sim_scenes/solar_system/earth_moon.py
sim_scenes/solar_system/earth_moon.py
+2
-0
sim_scenes/solar_system/jupiter_system.py
sim_scenes/solar_system/jupiter_system.py
+2
-0
sim_scenes/wonders/comets_jupiter.py
sim_scenes/wonders/comets_jupiter.py
+11
-5
sim_scenes/wonders/sun_earth_moon.py
sim_scenes/wonders/sun_earth_moon.py
+2
-1
sim_scenes/wonders/transit_of_venus_mercury.py
sim_scenes/wonders/transit_of_venus_mercury.py
+3
-0
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+1
-0
simulators/ursina/entities/planet.py
simulators/ursina/entities/planet.py
+2
-1
未找到文件。
sim_lab/earth_moon.py
浏览文件 @
ac4f1531
...
...
@@ -66,7 +66,10 @@ if __name__ == '__main__':
pass
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
...
...
sim_
scenes/science
/lagrangian_points.py
→
sim_
lab
/lagrangian_points.py
浏览文件 @
ac4f1531
文件已移动
sim_scenes/earth/earth_satellites.py
浏览文件 @
ac4f1531
...
...
@@ -51,7 +51,10 @@ if __name__ == '__main__':
info
[
"satellite"
].
planet
.
look_at
(
earth
.
planet
)
# 订阅事件后,上面2个函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/funny/dancing_with_jupiter.py
浏览文件 @
ac4f1531
...
...
@@ -44,7 +44,10 @@ if __name__ == '__main__':
create_line
(
from_pos
=
jupiter
.
planet
.
position
,
to_pos
=
dancer
.
planet
.
main_entity
.
position
,
color
=
color
.
white
)
# 订阅事件后,上面2个函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/science/earth_seasons.py
浏览文件 @
ac4f1531
...
...
@@ -96,7 +96,10 @@ if __name__ == '__main__':
# print(camera.rotation_y)
# 订阅事件后,上面2个函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/science/parabolic_curve.py
浏览文件 @
ac4f1531
...
...
@@ -16,18 +16,19 @@ from simulators.ursina.ursina_event import UrsinaEvent
def
create_ejected_object
(
velocity
,
raduis
,
trail_color
,
gravity_only_for
,
angle
=
10
):
"""
创建一个
被抛的
物体
创建一个
抛出
物体
@param velocity: 抛出去的速度
@param raduis:
物体
地球中心的半径
@param raduis: 地球中心的半径
@param trail_color: 轨迹颜色
@param gravity_only_for: 指定一个天体,被抛的物体的引力只对该天体有效
@param angle: 抛出去的角度(地平线夹角,默认为10)
@return:
"""
# 根据速度、角度获取矢量速度(vx、vy) -> vx² + vy² = velocity²
vx
,
vy
=
get_vector2d_velocity
(
velocity
,
angle
=
angle
)
football
=
Football
(
name
=
f
'物体速度:
{
velocity
}
'
,
mass
=
500
,
size_scale
=
1e3
,
trail_color
=
trail_color
,
init_position
=
[
0
,
raduis
,
0
],
init_velocity
=
[
vx
,
vy
,
0
],
gravity_only_for
=
[
gravity_only_for
])
# 仅适用于地球的重力,物体之间重力不要受到影响
football
=
Football
(
name
=
f
'物体速度:
{
velocity
}
'
,
mass
=
500
,
size_scale
=
1e3
,
trail_color
=
trail_color
,
init_position
=
[
0
,
raduis
+
500
,
0
],
init_velocity
=
[
vx
,
vy
,
0
],
gravity_only_for
=
[
gravity_only_for
])
return
football
...
...
@@ -38,28 +39,35 @@ if __name__ == '__main__':
# 地球在中心位置
earth
=
Earth
(
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
1
,
rotation_speed
=
0
,
texture
=
"earth_hd.jpg"
)
raduis
=
earth
.
raduis
+
300
# TODO:
4个不同的抛出速度
7.5km/s、8.5km/s、10km/s、11.2km/s(第二宇宙速度)
# 粉色
:velocity = 7.5,飞不出地球太远,就落地
raduis
=
earth
.
raduis
# TODO:
创建4个不同的抛出速度的物体,速度分别为:
7.5km/s、8.5km/s、10km/s、11.2km/s(第二宇宙速度)
# 粉色
拖尾:velocity = 7.5,飞不出地球太远,就落地(仅适用于地球的重力,物体之间重力不要受到影响)
obj0
=
create_ejected_object
(
velocity
=
7.5
,
raduis
=
raduis
,
trail_color
=
(
255
,
0
,
255
),
gravity_only_for
=
earth
)
# 红色:velocity = 8.5,飞不出地球太远,就落地
# 红色
拖尾
:velocity = 8.5,飞不出地球太远,就落地
obj1
=
create_ejected_object
(
velocity
=
8.5
,
raduis
=
raduis
,
trail_color
=
(
255
,
0
,
0
),
gravity_only_for
=
earth
)
# 绿色:velocity = 10,能飞出地球很远,但还是无法摆脱地球引力
# 绿色
拖尾
:velocity = 10,能飞出地球很远,但还是无法摆脱地球引力
obj2
=
create_ejected_object
(
velocity
=
10
,
raduis
=
raduis
,
trail_color
=
(
0
,
255
,
0
),
gravity_only_for
=
earth
)
# 蓝色:velocity = 11.2,脱离地球引力直接飞出。速度11.2千米/秒为脱离地球引力的速度叫第二宇宙速度
# 蓝色
拖尾
:velocity = 11.2,脱离地球引力直接飞出。速度11.2千米/秒为脱离地球引力的速度叫第二宇宙速度
obj3
=
create_ejected_object
(
velocity
=
11.2
,
raduis
=
raduis
,
trail_color
=
(
0
,
0
,
255
),
gravity_only_for
=
earth
)
bodies
=
[
earth
,
obj0
,
obj1
,
obj2
,
obj3
]
def
on_reset
():
"""
当按键盘的 “O” 键重置后,恢复所有抛出物的状态(引力有效),这样就可以反复观看
@return:
"""
for
obj
in
[
obj0
,
obj1
,
obj2
,
obj3
]:
obj
.
ignore_mass
=
False
def
on_timer_changed
(
time_data
:
TimeData
):
"""
定时触发,在10分钟后,进行碰撞判断,如果抛出物与地球相碰撞了,则抛出物体静止不
动
在运行中,每时每刻都会触发,对抛出物与地球的碰撞进行判断,如果碰到地球,则停止运
动
@param time_data:
@return:
"""
if
time_data
.
total_minutes
>
10
:
# 抛出物体10分钟后,再进行碰撞判断
for
obj
in
[
obj0
,
obj1
,
obj2
,
obj3
]:
# 循环判断每个抛出物与地球是否相碰撞
if
two_bodies_colliding
(
obj
,
earth
):
...
...
@@ -67,14 +75,11 @@ if __name__ == '__main__':
obj
.
stop_and_ignore_gravity
()
def
on_reset
():
for
obj
in
[
obj0
,
obj1
,
obj2
,
obj3
]:
obj
.
ignore_mass
=
False
# 订阅计时器事件(定时触发)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 订阅事件后,上面2个函数功能才会起作用
# 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
...
...
sim_scenes/science/speed_of_light_init.py
浏览文件 @
ac4f1531
...
...
@@ -94,7 +94,7 @@ class SpeedOfLightInit:
def
on_reset
(
self
):
"""
点击了重置按钮
触发
当按键盘的 “O” 键重置后会
触发
@return:
"""
if
hasattr
(
self
,
"run_speed_maps"
):
...
...
@@ -117,9 +117,12 @@ class SpeedOfLightInit:
raise
Exception
(
"请指定 SpeedOfLightInit.bodies"
)
# 订阅重新开始事件
# 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
self
.
on_ready
)
# 订阅计时器事件(记录已到达天体列表)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
self
.
on_timer_changed
)
def
light_body_input
(
self
,
key
):
...
...
sim_scenes/solar_system/earth_moon.py
浏览文件 @
ac4f1531
...
...
@@ -37,6 +37,8 @@ if __name__ == '__main__':
camera_look_at
(
earth
)
# 订阅事件后,上面的函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/solar_system/jupiter_system.py
浏览文件 @
ac4f1531
...
...
@@ -31,6 +31,8 @@ if __name__ == '__main__':
pass
# 订阅事件后,上面的函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/wonders/comets_jupiter.py
浏览文件 @
ac4f1531
...
...
@@ -65,7 +65,10 @@ if __name__ == '__main__':
def
on_reset
():
# 重置后恢复所有石头的状态(石头可见、引力有效)
"""
当按键盘的 “O” 键重置后,恢复所有石头的状态(石头可见、引力有效),这样就可以反复观看
@return:
"""
for
comet
in
comets
:
comet
.
set_visible
(
True
)
comet
.
ignore_mass
=
False
...
...
@@ -91,10 +94,13 @@ if __name__ == '__main__':
comet
.
explode
(
jupiter
)
# 订阅事件
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
# 重置了会触发 on_reset
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 运行中,每时每刻都会触发 on_timer_changed
# 订阅事件后,上面3个函数功能才会起作用
# 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent
.
on_reset_subscription
(
on_reset
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
...
...
sim_scenes/wonders/sun_earth_moon.py
浏览文件 @
ac4f1531
...
...
@@ -46,7 +46,8 @@ if __name__ == '__main__':
camera_look_at
(
moon
,
rotation_z
=
0
)
# 订阅计时器事件(定时触发)
# 订阅事件后,上面的函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
...
...
sim_scenes/wonders/transit_of_venus_mercury.py
浏览文件 @
ac4f1531
...
...
@@ -57,7 +57,10 @@ if __name__ == '__main__':
earth
.
look_at
(
sun
,
rotation_z
=
0
)
# 订阅事件后,上面2个函数功能才会起作用
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
...
...
simulators/ursina/entities/body_timer.py
浏览文件 @
ac4f1531
...
...
@@ -66,6 +66,7 @@ class BodyTimer(Singleton):
def
__init__
(
self
):
if
not
hasattr
(
self
,
"inited"
):
self
.
velocity_inc
=
1e-30
# 理论上数值越小越好,可以使用 1e-300 ,但建议使用:1e-30 # 0.00001
# 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent
.
on_reset_subscription
(
self
.
reset
)
UrsinaEvent
.
on_pause_subscription
(
self
.
pause
)
UrsinaEvent
.
on_start_subscription
(
self
.
start
)
...
...
simulators/ursina/entities/planet.py
浏览文件 @
ac4f1531
...
...
@@ -83,8 +83,9 @@ class Planet(Entity):
else
:
model
=
create_sphere
(
0.5
,
subdivisions
)
rotation
=
(
0
,
0
,
0
)
# 按键盘的 “O” 重置键会触发 on_reset
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
# 当对天体大小进行缩放的时候会触发 change_body_scale
UrsinaEvent
.
on_body_size_changed_subscription
(
self
.
change_body_scale
)
super
().
__init__
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录