Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
5a7a24dc
宇宙模拟器
项目概览
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看板
提交
5a7a24dc
编写于
12月 08, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
88367ce4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
189 addition
and
77 deletion
+189
-77
sim_lab/the_lost_planet.py
sim_lab/the_lost_planet.py
+189
-77
未找到文件。
sim_lab/the_lost_planet.py
浏览文件 @
5a7a24dc
...
@@ -14,6 +14,8 @@ from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky
...
@@ -14,6 +14,8 @@ 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.func
import
ext_fun_for_method
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
,
Vec3
,
distance
import
math
class
TheLostPlanetSim
(
UniverseSimScenes
):
class
TheLostPlanetSim
(
UniverseSimScenes
):
...
@@ -26,7 +28,7 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -26,7 +28,7 @@ class TheLostPlanetSim(UniverseSimScenes):
# inner_radius:内圆半径 outer_radius:外圆半径,subdivisions:细分数,控制圆环的细节和精度
# inner_radius:内圆半径 outer_radius:外圆半径,subdivisions:细分数,控制圆环的细节和精度
# self.asteroids.torus_zone = 4.7, 5.5, 64
# self.asteroids.torus_zone = 4.7, 5.5, 64
self
.
moon
=
Moon
(
size_scale
=
3e3
,
init_position
=
[
0
,
0
,
(
0.4
+
2.4
)
*
AU
],
distance_scale
=
1.76
)
self
.
moon
=
Moon
(
size_scale
=
3
.5
e3
,
init_position
=
[
0
,
0
,
(
0.4
+
2.4
)
*
AU
],
distance_scale
=
1.76
)
# ceres = Ceres(size_scale=3e3, distance_scale=1.7)
# ceres = Ceres(size_scale=3e3, distance_scale=1.7)
self
.
earth
=
Earth
(
size_scale
=
3e3
,
distance_scale
=
3.8
)
self
.
earth
=
Earth
(
size_scale
=
3e3
,
distance_scale
=
3.8
)
self
.
mars
=
Mars
(
size_scale
=
3e3
,
distance_scale
=
2.9
)
self
.
mars
=
Mars
(
size_scale
=
3e3
,
distance_scale
=
2.9
)
...
@@ -86,7 +88,10 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -86,7 +88,10 @@ class TheLostPlanetSim(UniverseSimScenes):
an
=
0.4
an
=
0.4
else
:
else
:
an
=
0.4
+
0.3
*
pow
(
2
,
planet_no
-
2
)
an
=
0.4
+
0.3
*
pow
(
2
,
planet_no
-
2
)
print
(
body
.
name
,
an
,
body
.
position
[
2
]
/
AU
)
# print(body.name, an, body.position[2] / AU)
self
.
step_index
=
0
self
.
init_steps
()
def
on_ready
(
self
):
def
on_ready
(
self
):
"""
"""
...
@@ -103,6 +108,13 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -103,6 +108,13 @@ class TheLostPlanetSim(UniverseSimScenes):
camera
.
look_at
(
self
.
jupiter
.
planet
)
camera
.
look_at
(
self
.
jupiter
.
planet
)
# camera.look_at(sun.planet)
# camera.look_at(sun.planet)
camera
.
rotation_z
-=
90
camera
.
rotation_z
-=
90
#
# self.moon.planet.update = lambda :None
# def moon_update():
# self.moon.planet.scale = 80
# # self.moon.planet.rotation_y += 10
#
# ext_fun_for_method(self.moon.planet, after_run_fun=moon_update)
# for i in range(10):
# for i in range(10):
# time.sleep(0.1)
# time.sleep(0.1)
...
@@ -113,6 +125,7 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -113,6 +125,7 @@ class TheLostPlanetSim(UniverseSimScenes):
# self.asteroids.planet.enabled = False
# self.asteroids.planet.enabled = False
self
.
moon
.
planet
.
enabled
=
False
self
.
moon
.
planet
.
enabled
=
False
# ceres.planet.enabled = False
# ceres.planet.enabled = False
# self.moon.planet.look_at(self.mars.planet)
def
set_alpha_animation
(
self
,
body
,
begin_alpha
,
end_alpha
,
interval
,
is_destroy
=
False
):
def
set_alpha_animation
(
self
,
body
,
begin_alpha
,
end_alpha
,
interval
,
is_destroy
=
False
):
from
ursina
import
destroy
from
ursina
import
destroy
...
@@ -142,26 +155,111 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -142,26 +155,111 @@ class TheLostPlanetSim(UniverseSimScenes):
if
is_destroy
and
not
planet
.
enabled
:
if
is_destroy
and
not
planet
.
enabled
:
destroy
(
planet
)
destroy
(
planet
)
# planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
# planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
# print(
planet.alpha
)
# print(
body, planet.alpha, planet.rotation_x, planet.rotation_y, planet.rotation_z
)
planet
.
update
=
alpha_animation
planet
.
update
=
alpha_animation
# ext_fun_for_method(planet, after_run_fun=alpha_animation)
# ext_fun_for_method(planet, after_run_fun=alpha_animation)
def
create_asteroid
(
self
,
init_angle
=
89.5
):
# def set_alpha_animation(self, body, begin_alpha, end_alpha, interval, is_destroy=False):
# from ursina import destroy
# if hasattr(body, "planet"):
# planet = body.planet
# else:
# planet = body
# planet.alpha = 0
#
# def alpha_animation():
# alpha = planet.alpha
# alpha += interval
# if alpha > 1:
# alpha = 1
# planet.enabled = (alpha > 0)
# planet.alpha = alpha
# # planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
# # print(body, planet.alpha, planet.rotation_x, planet.rotation_y, planet.rotation_z)
#
# planet.update = alpha_animation
# # ext_fun_for_method(planet, after_run_fun=alpha_animation)
# def moon_fade_in(self):
# """
# 月球渐渐显示
# @return:
# """
# # self.moon.planet.look_at(self.mars.planet)
# self.moon.planet.alpha = 0
# def alpha_animation():
# from ursina import Vec2,Vec4
# planet = self.moon.planet.main_entity
# alpha = planet.alpha
# alpha += 0.01
# planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
# planet.alpha = alpha
# planet.texture_offset = Vec2(0, 0)
# planet.texture_scale = Vec2(1, 1)
#
# self.moon.planet.update = alpha_animation # lambda: None
# self.set_alpha_animation(self.moon, 0.0, 1.0, 0.005)
#
# def moon_fade_in(self):
# from ursina import Vec4
# planet = self.moon.planet
# planet.alpha = 0
# def update_moon():
# alpha = planet.alpha
# alpha += 0.01
# if alpha > 1.0:
# alpha = 1.0
# planet.update = lambda: None
# planet.color = Vec4(planet.color[0], planet.color[1], planet.color[2], alpha)
# planet.alpha = alpha
#
# planet.update = update_moon
# def earth_fade_in(self):
# """
# 月球渐渐显示
# @return:
# """
# self.earth.planet.look_at(self.mars.planet)
# # self.moon.planet.update = lambda: None
# self.set_alpha_animation(self.earth, 0.0, 1.0, 0.005)
# def moon_fade_out(self):
# """
# 月球渐渐显示
# @return:
# """
# self.moon.planet.look_at(self.mars.planet)
# # self.moon.planet.update = lambda: None
# self.set_alpha_animation(self.moon, 1.0, 0.0, 0.005)
def
create_asteroid
(
self
,
init_angle
=
110
,
smooth
=
False
):
from
ursina
import
Entity
,
color
,
Vec3
from
ursina
import
Entity
,
color
,
Vec3
import
math
import
math
import
random
import
random
pos
=
self
.
moon
.
planet
.
position
# + Vec3()
pos
=
self
.
moon
.
planet
.
position
# + Vec3()
radius
=
self
.
moon
.
planet
.
position
[
2
]
+
40
*
random
.
random
()
-
20
# * moon.distance_scale
radius
=
self
.
moon
.
planet
.
position
[
2
]
+
50
*
random
.
random
()
-
15
# * moon.distance_scale
asteroid
=
Entity
(
model
=
'sphere'
,
position
=
pos
,
color
=
color
.
white
,
scale
=
1.5
)
asteroid
=
Entity
(
model
=
'sphere'
,
position
=
pos
,
color
=
color
.
white
,
scale
=
1.5
)
asteroid
.
s_angle
=
init_angle
asteroid
.
s_angle
=
init_angle
asteroid
.
init_pos
=
pos
y
=
10
*
random
.
random
()
-
5
y
=
10
*
random
.
random
()
-
5
speed
=
random
.
random
()
/
7
+
0.2
def
rotation
():
def
rotation
():
x
=
self
.
sun
.
planet
.
x
+
radius
*
math
.
cos
(
asteroid
.
s_angle
)
angle
=
math
.
pi
*
asteroid
.
s_angle
/
180
z
=
self
.
sun
.
planet
.
z
+
radius
*
math
.
sin
(
asteroid
.
s_angle
)
x
=
self
.
sun
.
planet
.
x
+
radius
*
math
.
cos
(
angle
)
asteroid
.
position
=
(
x
,
y
,
z
)
z
=
self
.
sun
.
planet
.
z
+
radius
*
math
.
sin
(
angle
)
speed
=
random
.
random
()
/
50
target_pos
=
Vec3
(
x
,
y
,
z
)
if
asteroid
.
init_pos
is
None
or
not
smooth
:
# angle = math.pi * asteroid.s_angle / 180
# x = self.sun.planet.x + radius * math.cos(angle)
# z = self.sun.planet.z + radius * math.sin(angle)
asteroid
.
position
=
target_pos
else
:
asteroid
.
look_at
(
target_pos
)
asteroid
.
position
+=
asteroid
.
forward
*
1.5
d
=
distance
(
asteroid
.
position
,
target_pos
)
if
d
<
3
:
asteroid
.
init_pos
=
None
asteroid
.
s_angle
+=
speed
asteroid
.
s_angle
+=
speed
asteroid
.
update
=
rotation
asteroid
.
update
=
rotation
...
@@ -169,7 +267,7 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -169,7 +267,7 @@ class TheLostPlanetSim(UniverseSimScenes):
def
create_asteroids
(
self
):
def
create_asteroids
(
self
):
self
.
asteroids
=
[]
self
.
asteroids
=
[]
for
i
in
range
(
5
00
):
for
i
in
range
(
4
00
):
self
.
asteroids
.
append
(
self
.
create_asteroid
(
i
))
self
.
asteroids
.
append
(
self
.
create_asteroid
(
i
))
# def clear_asteroids(self):
# def clear_asteroids(self):
...
@@ -202,6 +300,15 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -202,6 +300,15 @@ class TheLostPlanetSim(UniverseSimScenes):
self
.
moon
.
planet
.
update
=
lambda
:
None
self
.
moon
.
planet
.
update
=
lambda
:
None
self
.
set_alpha_animation
(
self
.
moon
,
0.0
,
1.0
,
0.005
)
self
.
set_alpha_animation
(
self
.
moon
,
0.0
,
1.0
,
0.005
)
# def moon_fade_out(self):
# """
# 月球渐渐显示
# @return:
# """
# self.moon.planet.look_at(self.mars.planet)
# # self.moon.planet.update = lambda: None
# self.set_alpha_animation(self.moon, 1.0, 0.0, 0.005)
def
moon_renovation
(
self
):
def
moon_renovation
(
self
):
"""
"""
月球改造中
月球改造中
...
@@ -209,44 +316,98 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -209,44 +316,98 @@ class TheLostPlanetSim(UniverseSimScenes):
"""
"""
if
not
hasattr
(
self
,
"moon_redesign_last_time"
):
if
not
hasattr
(
self
,
"moon_redesign_last_time"
):
self
.
moon_redesign_last_time
=
time
.
time
()
self
.
moon_redesign_last_time
=
time
.
time
()
self
.
asteroid_num
=
0
c_time
=
time
.
time
()
c_time
=
time
.
time
()
# set_alpha_animation(asteroids, 0.0, 1.0, 0.01)
# set_alpha_animation(asteroids, 0.0, 1.0, 0.01)
if
c_time
-
self
.
moon_redesign_last_time
>
0.02
:
if
c_time
-
self
.
moon_redesign_last_time
>
0.02
:
self
.
moon_redesign_last_time
=
c_time
self
.
moon_redesign_last_time
=
c_time
self
.
create_asteroid
()
self
.
create_asteroid
(
smooth
=
True
)
self
.
asteroid_num
+=
1
def
moon_move_to_target_and_rotation
(
self
,
target
,
rotation_radius
,
end_angle
,
end_tag
,
def
moon_move_to_target_and_rotation
(
self
,
target
,
rotation_radius
,
end_angle
,
end_tag
,
forward
=
0.1
,
forward
,
angle_val
=
0.08
):
angle_val
):
from
ursina
import
camera
,
Vec3
,
distance
import
math
if
hasattr
(
target
,
"planet"
):
if
hasattr
(
target
,
"planet"
):
target_planet
=
target
.
planet
.
main_entity
target_planet
=
target
.
planet
.
main_entity
else
:
else
:
target_planet
=
target
.
main_entity
target_planet
=
target
.
main_entity
self
.
moon
.
planet
.
look_at
(
target_planet
)
if
not
hasattr
(
target_planet
,
"is_forward"
):
target_planet
.
is_forward
=
True
d
=
distance
(
self
.
moon
.
planet
,
target_planet
)
if
target_planet
.
is_forward
:
if
d
>
rotation_radius
:
target_pos
=
target_planet
.
position
+
Vec3
(
-
rotation_radius
,
0
,
0
)
self
.
moon
.
planet
.
position
+=
self
.
moon
.
planet
.
forward
*
forward
self
.
moon
.
planet
.
look_at
(
target_pos
)
d
=
distance
(
self
.
moon
.
planet
,
target_pos
)
if
d
>
3
:
self
.
moon
.
planet
.
position
+=
self
.
moon
.
planet
.
forward
*
forward
else
:
target_planet
.
is_forward
=
False
else
:
else
:
if
not
hasattr
(
target_planet
,
"moon_angle"
):
if
not
hasattr
(
target_planet
,
"moon_angle"
):
setattr
(
target_planet
,
"moon_angle"
,
90
)
setattr
(
target_planet
,
"moon_angle"
,
180
)
moon_angle
=
getattr
(
target_planet
,
"moon_angle"
)
moon_angle
=
getattr
(
target_planet
,
"moon_angle"
)
x
=
target_planet
.
x
+
rotation_radius
*
math
.
cos
(
moon_angle
)
z
=
target_planet
.
z
+
rotation_radius
*
math
.
sin
(
moon_angle
)
angle
=
math
.
pi
*
moon_angle
/
180
x
=
target_planet
.
x
+
rotation_radius
*
math
.
cos
(
angle
)
z
=
target_planet
.
z
+
rotation_radius
*
math
.
sin
(
angle
)
self
.
moon
.
planet
.
position
=
(
x
,
0
,
z
)
self
.
moon
.
planet
.
position
=
(
x
,
0
,
z
)
setattr
(
target_planet
,
"moon_angle"
,
moon_angle
+
angle_val
)
setattr
(
target_planet
,
"moon_angle"
,
moon_angle
+
angle_val
)
if
moon_angle
>=
end_angle
:
if
moon_angle
>=
end_angle
:
setattr
(
self
,
end_tag
,
True
)
setattr
(
self
,
end_tag
,
True
)
self
.
step_index
+=
1
# print("moon_angle", moon_angle)
# print("moon_angle", moon_angle)
def
init_steps
(
self
):
def
step_05
():
if
not
hasattr
(
self
,
"moon_around_mars"
):
# setattr(self, "step_04", True)
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
mars
,
rotation_radius
=
12
,
end_angle
=
180
+
360
*
3
,
end_tag
=
"moon_around_mars"
,
forward
=
0.02
,
angle_val
=
0.8
)
def
step_06
():
if
not
hasattr
(
self
,
"moon_around_earth"
):
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
earth
,
rotation_radius
=
15
,
end_angle
=
7200
,
end_tag
=
"moon_around_earth"
,
forward
=
0.02
,
angle_val
=
1
)
self
.
steps
=
[
(
self
.
asteroid_fade_in
,
3
,
1
),
(
self
.
asteroid_fade_out
,
3
,
1
),
(
self
.
moon_fade_in
,
3
,
1
),
(
self
.
moon_renovation
,
10
,
-
1
),
(
step_05
,
-
1
,
-
1
),
(
step_06
,
-
1
,
-
1
),
]
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
self
,
time_data
):
if
time_data
.
years
>
1
:
if
self
.
step_index
>
len
(
self
.
steps
)
-
1
:
self
.
step_index
=
len
(
self
.
steps
)
-
1
fun
,
wait_years
,
run_times
=
self
.
steps
[
self
.
step_index
]
if
not
hasattr
(
self
,
f
"
{
fun
.
__name__
}
_wait_years"
):
setattr
(
self
,
f
"
{
fun
.
__name__
}
_wait_years"
,
time_data
.
years
)
setattr
(
self
,
f
"
{
fun
.
__name__
}
_run_times"
,
0
)
fun_run_times
=
getattr
(
self
,
f
"
{
fun
.
__name__
}
_run_times"
)
if
fun_run_times
<
run_times
or
run_times
<
0
:
fun
()
setattr
(
self
,
f
"
{
fun
.
__name__
}
_run_times"
,
fun_run_times
+
1
)
fun_wait_years
=
getattr
(
self
,
f
"
{
fun
.
__name__
}
_wait_years"
)
if
wait_years
+
fun_wait_years
<
time_data
.
years
and
wait_years
>
0
:
self
.
step_index
+=
1
# print(self.step_index, fun.__name__)
def
on_timer_changed2
(
self
,
time_data
):
from
ursina
import
camera
,
Vec3
,
distance
from
ursina
import
camera
,
Vec3
,
distance
import
math
import
math
...
@@ -270,66 +431,16 @@ class TheLostPlanetSim(UniverseSimScenes):
...
@@ -270,66 +431,16 @@ class TheLostPlanetSim(UniverseSimScenes):
setattr
(
self
,
"step_04"
,
True
)
setattr
(
self
,
"step_04"
,
True
)
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
mars
,
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
mars
,
rotation_radius
=
12
,
rotation_radius
=
12
,
end_angle
=
11
0
,
end_angle
=
72
0
,
end_tag
=
"moon_around_mars"
,
end_tag
=
"moon_around_mars"
,
forward
=
0.03
,
angle_val
=
0.05
)
forward
=
0.03
,
angle_val
=
3
)
# self.moon.planet.look_at(self.mars.planet)
# radius = 12
# d = distance(self.moon.planet, self.mars.planet.position)
# if d > 12:
# self.moon.planet.position += self.moon.planet.forward * 0.1
# else:
# if not hasattr(self.mars, "moon_angle"):
# setattr(self.mars, "moon_angle", 90)
#
# moon_angle = getattr(self.mars, "moon_angle")
# x = self.mars.planet.x + radius * math.cos(moon_angle)
# z = self.mars.planet.z + radius * math.sin(moon_angle)
# self.moon.planet.position = (x, 0, z)
#
# setattr(self.mars, "moon_angle", moon_angle + 0.08)
#
# if moon_angle >= 110:
# setattr(self.moon, "mars_rotation", True)
# print("moon_angle", moon_angle)
elif
hasattr
(
self
,
"moon_around_mars"
)
and
not
hasattr
(
self
,
"moon_around_earth"
):
elif
hasattr
(
self
,
"moon_around_mars"
)
and
not
hasattr
(
self
,
"moon_around_earth"
):
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
earth
,
self
.
moon_move_to_target_and_rotation
(
target
=
self
.
earth
,
rotation_radius
=
15
,
rotation_radius
=
15
,
end_angle
=
36
0
,
end_angle
=
72
0
,
end_tag
=
"moon_around_earth"
,
end_tag
=
"moon_around_earth"
,
forward
=
0.03
,
angle_val
=
0.05
)
forward
=
0.03
,
angle_val
=
3
)
# earth_target = self.earth.planet.main_entity
# self.moon.planet.look_at(earth_target)
# radius = 15
# d = distance(self.moon.planet.position, earth_target.position)
# if d > 15:
# self.moon.planet.position += self.moon.planet.forward * 0.1
# else:
# if not hasattr(self.earth, "moon_angle"):
# setattr(self.earth, "moon_angle", 90)
#
# moon_angle = getattr(self.earth, "moon_angle")
# x = earth_target.x + radius * math.cos(moon_angle)
# z = earth_target.z + radius * math.sin(moon_angle)
# self.moon.planet.position = (x, 0, z)
#
# setattr(self.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)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -355,4 +466,5 @@ if __name__ == '__main__':
...
@@ -355,4 +466,5 @@ if __name__ == '__main__':
timer_enabled
=
True
,
timer_enabled
=
True
,
show_timer
=
True
,
show_timer
=
True
,
cosmic_bg
=
''
,
cosmic_bg
=
''
,
# show_trail=True,
show_grid
=
False
)
show_grid
=
False
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录