Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
e03e0272
宇宙模拟器
项目概览
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看板
提交
e03e0272
编写于
12月 07, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
6c170d76
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
126 addition
and
19 deletion
+126
-19
sim_lab/the_lost_planet.py
sim_lab/the_lost_planet.py
+126
-19
未找到文件。
sim_lab/the_lost_planet.py
浏览文件 @
e03e0272
...
@@ -10,6 +10,7 @@ from bodies import Sun, Mercury, Venus, Earth, Mars, Moon, Ceres, Jupiter, Satur
...
@@ -10,6 +10,7 @@ from bodies import Sun, Mercury, Venus, Earth, Mars, Moon, Ceres, Jupiter, Satur
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
,
AU
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_DAY
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
create_sphere_sky
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
create_sphere_sky
from
sim_scenes.universe_sim_scenes
import
UniverseSimScenes
from
sim_scenes.universe_sim_scenes
import
UniverseSimScenes
from
simulators.func
import
ext_fun_for_method
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -19,18 +20,20 @@ if __name__ == '__main__':
...
@@ -19,18 +20,20 @@ if __name__ == '__main__':
# 环状星群带(inner_radius, outer_radius, subdivisions)
# 环状星群带(inner_radius, outer_radius, subdivisions)
# inner_radius:内圆半径 outer_radius:外圆半径,subdivisions:细分数,控制圆环的细节和精度
# inner_radius:内圆半径 outer_radius:外圆半径,subdivisions:细分数,控制圆环的细节和精度
asteroids
.
torus_zone
=
4.
2
,
5
,
64
asteroids
.
torus_zone
=
4.
7
,
5.
5
,
64
moon
=
Moon
(
size_scale
=
3e3
,
init_position
=
[
0
,
0
,
(
0.4
+
2.4
)
*
AU
],
distance_scale
=
1.
7
)
moon
=
Moon
(
size_scale
=
3e3
,
init_position
=
[
0
,
0
,
(
0.4
+
2.4
)
*
AU
],
distance_scale
=
1.
8
)
ceres
=
Ceres
(
size_scale
=
3e3
,
distance_scale
=
1.7
)
ceres
=
Ceres
(
size_scale
=
3e3
,
distance_scale
=
1.7
)
jupiter
=
Jupiter
(
size_scale
=
0.68e3
,
distance_scale
=
1.05
)
earth
=
Earth
(
size_scale
=
3e3
,
distance_scale
=
3.8
)
saturn
=
Saturn
(
size_scale
=
0.68e3
,
distance_scale
=
0.72
)
mars
=
Mars
(
size_scale
=
3e3
,
distance_scale
=
2.9
)
jupiter
=
Jupiter
(
size_scale
=
0.68e3
,
distance_scale
=
1.15
)
saturn
=
Saturn
(
size_scale
=
0.68e3
,
distance_scale
=
0.74
)
bodies
=
[
bodies
=
[
sun
,
sun
,
Mercury
(
size_scale
=
3e3
,
distance_scale
=
7
),
# 水星放大 4000 倍
Mercury
(
size_scale
=
3e3
,
distance_scale
=
7
),
# 水星放大 4000 倍
Venus
(
size_scale
=
3e3
,
distance_scale
=
4.3
),
# 金星放大 4000 倍
Venus
(
size_scale
=
3e3
,
distance_scale
=
4.3
),
# 金星放大 4000 倍
Earth
(
size_scale
=
3e3
,
distance_scale
=
3.5
)
,
# 地球放大 4000 倍
earth
,
# 地球放大 4000 倍
Mars
(
size_scale
=
3e3
,
distance_scale
=
2.6
)
,
# 火星放大 4000 倍
mars
,
# 火星放大 4000 倍
asteroids
,
asteroids
,
moon
,
moon
,
ceres
,
ceres
,
...
@@ -89,44 +92,148 @@ if __name__ == '__main__':
...
@@ -89,44 +92,148 @@ if __name__ == '__main__':
"""
"""
from
ursina
import
camera
,
Vec3
from
ursina
import
camera
,
Vec3
# 创建天空
# 创建天空
create_sphere_sky
(
scale
=
20000
)
create_sphere_sky
(
scale
=
20000
,
rotation_x
=
0
,
rotation_y
=
80
)
camera
.
clip_plane_near
=
0.1
camera
.
clip_plane_near
=
0.1
camera
.
clip_plane_far
=
1000000
camera
.
clip_plane_far
=
1000000
camera
.
look_at
(
jupiter
.
planet
)
# camera.look_at(saturn.planet)
# camera.look_at(sun.planet)
# camera.look_at(sun.planet)
# camera.rotation_y
= 90
camera
.
rotation_z
-
=
90
# UniverseSimScenes.show_grid_axises()
# UniverseSimScenes.show_grid_axises()
# asteroids.planet.enabled = False
asteroids
.
planet
.
enabled
=
False
# moon.planet.enabled = False
moon
.
planet
.
enabled
=
False
ceres
.
planet
.
enabled
=
False
def
set_alpha_animation
(
body
,
begin_alpha
,
end_alpha
,
interval
):
planet
=
body
.
planet
planet
.
alpha
=
begin_alpha
if
begin_alpha
>
end_alpha
:
interval
=
-
abs
(
interval
)
else
:
interval
=
abs
(
interval
)
origin_update
=
planet
.
update
def
alpha_animation
():
from
ursina
import
camera
,
Vec4
origin_update
()
alpha
=
planet
.
alpha
alpha
+=
interval
if
(
interval
>
0
and
alpha
>=
end_alpha
)
or
(
interval
<
0
and
alpha
<=
end_alpha
):
alpha
=
end_alpha
planet
.
update
=
origin_update
planet
.
enabled
=
(
alpha
>
0
)
planet
.
alpha
=
alpha
# planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
print
(
planet
.
alpha
)
planet
.
update
=
alpha_animation
# ext_fun_for_method(planet, after_run_fun=alpha_animation)
#
#
# def after_ready():
# def after_ready():
# from ursina import camera, Vec3
# from ursina import camera, Vec3
# camera.position = Vec3(0,149.60,-665.76)
# camera.position = Vec3(0,149.60,-665.76)
# camera.world_position = Vec3(-14.71,-98.38,0)
# camera.world_position = Vec3(-14.71,-98.38,0)
#
def
on_timer_changed
(
time_data
):
def
on_timer_changed
(
time_data
):
from
ursina
import
camera
,
Vec3
from
ursina
import
camera
,
Vec3
,
distance
camera
.
position
=
Vec3
(
0
,
149.60
,
-
665.76
)
import
math
camera
.
world_position
=
Vec3
(
-
14.71
,
-
98.38
,
0
)
# print(time_data.years)
if
time_data
.
years
>
1
and
not
hasattr
(
asteroids
,
"years_1"
):
set_alpha_animation
(
asteroids
,
0.0
,
1.0
,
0.01
)
setattr
(
asteroids
,
"years_1"
,
True
)
elif
time_data
.
years
>
4
and
not
hasattr
(
asteroids
,
"years_5"
):
set_alpha_animation
(
asteroids
,
1.0
,
0.0
,
0.01
)
setattr
(
asteroids
,
"years_5"
,
True
)
elif
time_data
.
years
>
6
and
not
hasattr
(
moon
,
"years_6"
):
moon
.
planet
.
look_at
(
mars
.
planet
)
moon
.
planet
.
update
=
lambda
:
None
set_alpha_animation
(
moon
,
0.0
,
1.0
,
0.005
)
setattr
(
moon
,
"years_6"
,
True
)
elif
time_data
.
years
>
8
and
not
hasattr
(
asteroids
,
"years_8"
):
set_alpha_animation
(
asteroids
,
0.0
,
1.0
,
0.01
)
setattr
(
asteroids
,
"years_8"
,
True
)
if
time_data
.
years
>
8
and
not
hasattr
(
moon
,
"years_8"
):
moon
.
planet
.
look_at
(
mars
.
planet
)
radius
=
12
d
=
distance
(
moon
.
planet
,
mars
.
planet
.
position
)
if
d
>
12
:
moon
.
planet
.
position
+=
moon
.
planet
.
forward
*
0.1
else
:
if
not
hasattr
(
mars
,
"moon_angle"
):
setattr
(
mars
,
"moon_angle"
,
90
)
moon_angle
=
getattr
(
mars
,
"moon_angle"
)
x
=
mars
.
planet
.
x
+
radius
*
math
.
cos
(
moon_angle
)
z
=
mars
.
planet
.
z
+
radius
*
math
.
sin
(
moon_angle
)
moon
.
planet
.
position
=
(
x
,
0
,
z
)
setattr
(
mars
,
"moon_angle"
,
moon_angle
+
0.08
)
if
moon_angle
>=
110
:
setattr
(
moon
,
"years_8"
,
True
)
print
(
"moon_angle"
,
moon_angle
)
elif
hasattr
(
mars
,
"moon_angle"
)
and
not
hasattr
(
moon
,
"earth_rotation"
):
earth_target
=
earth
.
planet
.
main_entity
moon
.
planet
.
look_at
(
earth_target
)
radius
=
15
d
=
distance
(
moon
.
planet
.
position
,
earth_target
.
position
)
if
d
>
15
:
moon
.
planet
.
position
+=
moon
.
planet
.
forward
*
0.1
else
:
if
not
hasattr
(
earth
,
"moon_angle"
):
setattr
(
earth
,
"moon_angle"
,
90
)
moon_angle
=
getattr
(
earth
,
"moon_angle"
)
x
=
earth_target
.
x
+
radius
*
math
.
cos
(
moon_angle
)
z
=
earth_target
.
z
+
radius
*
math
.
sin
(
moon_angle
)
moon
.
planet
.
position
=
(
x
,
0
,
z
)
setattr
(
earth
,
"moon_angle"
,
moon_angle
+
0.08
)
if
moon_angle
>=
360
*
2
+
90
:
setattr
(
moon
,
"earth_rotation"
,
True
)
print
(
"moon_angle"
,
moon_angle
)
# moon.planet.world_rotation_z = 90
# moon.planet.position += moon.planet.right * 0.1
# setattr(moon, "years_8", True)
# elif time_data.years > 15 and not hasattr(moon, "years_15"):
# set_alpha_animation(moon, 1.0, 0.0, 0.05)
# setattr(moon, "years_15", True)
# UniverseSimScenes.set_window_size((1920, 1079), False)
# 运行前会触发 on_ready
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# UrsinaEvent.after_ready_subscription(after_ready)
# UrsinaEvent.after_ready_subscription(after_ready)
#
UrsinaEvent.on_timer_changed_subscription(on_timer_changed)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
ursina_run
(
bodies
,
SECONDS_PER_YEAR
,
SECONDS_PER_YEAR
,
gravity_works
=
False
,
gravity_works
=
False
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
show_exit_button
=
False
,
show_control_info
=
False
,
show_camera_info
=
False
,
# position=(0, 2 * AU, -11 * AU),
# position=(0, 20 * AU, 10 * AU),
# position=(0, 20 * AU, 10 * AU),
# position=(0, 20 * AU, 0
),
position
=
(
5.5
*
AU
,
AU
,
5
*
AU
),
timer_enabled
=
True
,
timer_enabled
=
True
,
show_timer
=
True
,
cosmic_bg
=
''
,
cosmic_bg
=
''
,
show_grid
=
False
)
show_grid
=
False
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录