Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
c8386bbc
宇宙模拟器
项目概览
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看板
提交
c8386bbc
编写于
6月 27, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
20948d9a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
14 addition
and
7 deletion
+14
-7
sim_scenes/science/jupiter_protects_earth.py
sim_scenes/science/jupiter_protects_earth.py
+14
-7
未找到文件。
sim_scenes/science/jupiter_protects_earth.py
浏览文件 @
c8386bbc
...
@@ -16,7 +16,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
...
@@ -16,7 +16,7 @@ from simulators.ursina.ursina_event import UrsinaEvent
import
random
import
random
def
create_comet
(
index
,
raduis
):
def
create_comet
(
index
,
raduis
,
gravity_only_for
):
"""
"""
随机生成石头(随机位置、随机初始速度、随机大小、随机旋转)
随机生成石头(随机位置、随机初始速度、随机大小、随机旋转)
@param index: 索引号
@param index: 索引号
...
@@ -37,7 +37,7 @@ def create_comet(index, raduis):
...
@@ -37,7 +37,7 @@ def create_comet(index, raduis):
rock
=
create_rock
(
rock
=
create_rock
(
no
=
index
%
8
+
1
,
name
=
f
'岩石
{
index
+
1
}
'
,
mass
=
4.4e10
,
no
=
index
%
8
+
1
,
name
=
f
'岩石
{
index
+
1
}
'
,
mass
=
4.4e10
,
size_scale
=
size_scale
,
color
=
(
255
,
200
,
0
),
size_scale
=
size_scale
,
color
=
(
255
,
200
,
0
),
init_position
=
pos
,
init_velocity
=
vel
,
init_position
=
pos
,
init_velocity
=
vel
,
gravity_only_for
=
gravity_only_for
)
)
# 给石头一个随机旋转的方向和值
# 给石头一个随机旋转的方向和值
...
@@ -46,6 +46,8 @@ def create_comet(index, raduis):
...
@@ -46,6 +46,8 @@ def create_comet(index, raduis):
return
rock
return
rock
colliding_count
=
[
0
,
0
,
0
]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
"""
"""
彗木保护地球模拟
彗木保护地球模拟
...
@@ -56,13 +58,13 @@ if __name__ == '__main__':
...
@@ -56,13 +58,13 @@ if __name__ == '__main__':
bodies
=
[
sun
,
jupiter
,
earth
]
bodies
=
[
sun
,
jupiter
,
earth
]
for
body
in
bodies
:
for
body
in
bodies
:
body
.
rotation_speed
/=
20
# 自转速度降低10
0倍
body
.
rotation_speed
/=
10
# 自转速度降低1
0倍
comets
=
[]
comets
=
[]
for
i
in
range
(
15
):
for
i
in
range
(
50
):
# 随机生成石头
# 随机生成
50
石头
comet
=
create_comet
(
i
,
jupiter
.
position
[
2
]
*
2
)
comet
=
create_comet
(
i
,
jupiter
.
position
[
2
]
*
2
,
gravity_only_for
=
[
sun
,
jupiter
,
earth
]
)
bodies
.
append
(
comet
)
bodies
.
append
(
comet
)
comets
.
append
(
comet
)
comets
.
append
(
comet
)
...
@@ -70,19 +72,24 @@ if __name__ == '__main__':
...
@@ -70,19 +72,24 @@ if __name__ == '__main__':
def
on_timer_changed
(
time_data
:
TimeData
):
def
on_timer_changed
(
time_data
:
TimeData
):
# 运行中,每时每刻都会触发
# 运行中,每时每刻都会触发
for
comet
in
comets
:
for
comet
in
comets
:
if
comet
.
visi
bled
:
if
comet
.
planet
.
ena
bled
:
# 如果是否可见,则旋转石头
# 如果是否可见,则旋转石头
comet
.
planet
.
rotation
+=
comet
.
rotation
comet
.
planet
.
rotation
+=
comet
.
rotation
# 循环判断每个石头与木星是否相碰撞,如果相碰撞就爆炸
# 循环判断每个石头与木星是否相碰撞,如果相碰撞就爆炸
if
two_bodies_colliding
(
comet
,
jupiter
):
if
two_bodies_colliding
(
comet
,
jupiter
):
# 将石头隐藏、设置引力无效后,展示爆炸效果
# 将石头隐藏、设置引力无效后,展示爆炸效果
comet
.
explode
(
jupiter
)
comet
.
explode
(
jupiter
)
colliding_count
[
1
]
+=
1
elif
two_bodies_colliding
(
comet
,
sun
):
elif
two_bodies_colliding
(
comet
,
sun
):
# 将石头隐藏、设置引力无效后,展示爆炸效果
# 将石头隐藏、设置引力无效后,展示爆炸效果
comet
.
explode
(
sun
)
comet
.
explode
(
sun
)
colliding_count
[
0
]
+=
1
elif
two_bodies_colliding
(
comet
,
earth
):
elif
two_bodies_colliding
(
comet
,
earth
):
# 将石头隐藏、设置引力无效后,展示爆炸效果
# 将石头隐藏、设置引力无效后,展示爆炸效果
comet
.
explode
(
earth
)
comet
.
explode
(
earth
)
colliding_count
[
2
]
+=
1
print
(
"Sun:%s Jupiter:%s Earth:%s"
%
(
colliding_count
[
0
],
colliding_count
[
1
],
colliding_count
[
2
]))
# def on_reset():
# def on_reset():
"""
"""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录