Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
aa5041bc
宇宙模拟器
项目概览
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看板
提交
aa5041bc
编写于
5月 03, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
42363daa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
13 deletion
+50
-13
sim_scenes/earth/earth_moon6.py
sim_scenes/earth/earth_moon6.py
+50
-13
未找到文件。
sim_scenes/earth/earth_moon6.py
浏览文件 @
aa5041bc
# -*- coding:utf-8 -*-
# title :地月场景模拟
# description :地
月
场景模拟
# title :地月
球
场景模拟
# description :地
球、6个月球
场景模拟
# author :Python超人
# date :2023-05-01
# link :https://gitcode.net/pythoncr/
...
...
@@ -8,29 +8,66 @@
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
from
sim_scenes.func
import
ursina_run
from
sim_scenes.func
import
ursina_run
,
two_bodies_colliding
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_event
import
UrsinaEvent
if
__name__
==
'__main__'
:
"""
地球、6个月球
"""
# 地球在中心位置
e
=
Earth
(
init_position
=
[
0
,
0
,
0
],
texture
=
"earth_hd.jpg"
,
init_velocity
=
[
0
,
0
,
0
])
earth
=
Earth
(
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
rotation_speed
=
0
,
texture
=
"earth_hd.jpg"
)
D
=
earth
.
diameter
*
1.2
init_vel
=
5.116
# 在地球周围创建 6 个月球(初速度为0)
bodies
=
[
e
,
Moon
(
init_position
=
[
e
.
diameter
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球右面
Moon
(
init_position
=
[
-
e
.
diameter
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球左面
Moon
(
init_position
=
[
0
,
e
.
diameter
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球上面
Moon
(
init_position
=
[
0
,
-
e
.
diameter
,
0
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球下面
Moon
(
init_position
=
[
0
,
0
,
e
.
diameter
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球前面
Moon
(
init_position
=
[
0
,
0
,
-
e
.
diameter
],
init_velocity
=
[
0
,
0
,
0
]),
# 月球在地球后面
e
arth
,
Moon
(
init_position
=
[
D
,
0
,
0
],
init_velocity
=
[
0
,
0
,
init_vel
]),
# 月球在地球右面
Moon
(
init_position
=
[
-
D
,
0
,
0
],
init_velocity
=
[
0
,
0
,
-
init_vel
]),
# 月球在地球左面
Moon
(
init_position
=
[
0
,
D
,
0
],
init_velocity
=
[
init_vel
,
0
,
0
]),
# 月球在地球上面
Moon
(
init_position
=
[
0
,
-
D
,
0
],
init_velocity
=
[
-
init_vel
,
0
,
0
]),
# 月球在地球下面
Moon
(
init_position
=
[
0
,
0
,
D
],
init_velocity
=
[
0
,
init_vel
,
0
]),
# 月球在地球前面
Moon
(
init_position
=
[
0
,
0
,
-
D
],
init_velocity
=
[
0
,
-
init_vel
,
0
]),
# 月球在地球后面
]
moons
=
bodies
[
1
:]
def
on_reset
():
"""
当按键盘的 “O” 键重置后,恢复所有抛出物的状态(引力有效),这样就可以反复观看
@return:
"""
for
moon
in
moons
:
moon
.
ignore_mass
=
False
def
on_timer_changed
(
time_data
:
TimeData
):
"""
在运行中,每时每刻都会触发,对抛出物与地球的碰撞进行判断,如果碰到地球,则停止运动
@param time_data:
@return:
"""
for
moon
in
moons
:
# 循环判断每个抛出物与地球是否相碰撞
if
two_bodies_colliding
(
moon
,
earth
):
# 如果抛出物与地球相碰撞了,则静止不动(抛出物停止并忽略引力)
moon
.
stop_and_ignore_gravity
()
# 订阅事件后,上面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:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_HOUR
/
1
0
,
position
=
(
0
,
0
,
-
4
*
e
.
diameter
),
ursina_run
(
bodies
,
SECONDS_PER_HOUR
/
1
5
,
position
=
(
0
,
0
,
-
4
*
e
arth
.
diameter
),
show_trail
=
True
,
show_timer
=
True
,
view_closely
=
0.001
)
# 近距离观看 view_closely=True或0.001
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录