Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
4a933690
宇宙模拟器
项目概览
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看板
“03c9e3afb77318bcbe290b37dfc332bb22957312”上不存在“objs/water_drop.py”
提交
4a933690
编写于
11月 17, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
b2cf7e80
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
157 addition
and
143 deletion
+157
-143
bodies/__init__.py
bodies/__init__.py
+2
-0
bodies/universe_body.py
bodies/universe_body.py
+77
-0
sim_lab/wormhole_sim.py
sim_lab/wormhole_sim.py
+78
-143
未找到文件。
bodies/__init__.py
浏览文件 @
4a933690
...
@@ -43,3 +43,5 @@ from bodies.fixed_stars.procyon import Procyon # 南河三
...
@@ -43,3 +43,5 @@ from bodies.fixed_stars.procyon import Procyon # 南河三
#
#
from
bodies.color_body
import
ColorBody
from
bodies.color_body
import
ColorBody
from
bodies.universe_body
import
UniverseBody
bodies/universe_body.py
0 → 100644
浏览文件 @
4a933690
# -*- coding:utf-8 -*-
# title :宇宙体
# description :模拟一个宇宙体
# author :Python超人
# date :2023-11-17
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
from
bodies
import
Body
class
UniverseBody
(
Body
):
def
__init__
(
self
,
name
=
"宇宙体"
,
mass
=
1.9891e35
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
color
=
(
0
,
0
,
0
),
texture
=
None
,
density
=
1.408e20
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
0
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
density
,
"color"
:
color
,
"texture"
:
texture
,
"size_scale"
:
size_scale
*
10000
,
"distance_scale"
:
distance_scale
,
"rotation_speed"
:
rotation_speed
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"show_name"
:
show_name
}
super
().
__init__
(
**
params
)
# self.set_resolution(50)
self
.
set_ignore_gravity
(
True
)
self
.
set_light_disable
(
False
)
class
OursUniverse
(
UniverseBody
):
def
__init__
(
self
,
name
=
"我们的宇宙"
,
size_scale
=
1.0
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]):
params
=
{
"name"
:
name
,
"mass"
:
1.9891e35
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
1.408e20
,
# "color": color,
"texture"
:
'bg_pan.jpg'
,
"size_scale"
:
size_scale
,
# "distance_scale": distance_scale,
# "ignore_mass": ignore_mass,
# "trail_color": trail_color,
# "show_name": show_name
}
super
().
__init__
(
**
params
)
def
create_universe_body
(
name
,
texture
,
size_scale
=
1.0
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]):
params
=
{
"name"
:
name
,
"mass"
:
1.9891e35
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
1.408e20
,
# "color": color,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
}
return
UniverseBody
(
**
params
)
sim_lab/wormhole_sim.py
浏览文件 @
4a933690
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
# python_version :3.9
# python_version :3.9
# ==============================================================================
# ==============================================================================
from
bodies
import
Sun
,
Earth
from
bodies
import
Sun
,
Earth
from
bodies.universe_body
import
create_universe_body
from
common.consts
import
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
,
AU
from
common.consts
import
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
,
SECONDS_PER_YEAR
,
AU
from
objs
import
Obj
,
SpaceShip
,
StarWarsSpeeder
,
ScifiGunship
,
SciFiBomber
,
CoreValagaClas
from
objs
import
Obj
,
SpaceShip
,
StarWarsSpeeder
,
ScifiGunship
,
SciFiBomber
,
CoreValagaClas
from
sim_scenes.func
import
mayavi_run
,
mpl_run
,
ursina_run
,
camera_look_at
,
two_bodies_colliding
from
sim_scenes.func
import
mayavi_run
,
mpl_run
,
ursina_run
,
camera_look_at
,
two_bodies_colliding
...
@@ -15,114 +16,37 @@ from ursina import camera, application, lerp
...
@@ -15,114 +16,37 @@ from ursina import camera, application, lerp
from
bodies
import
Body
from
bodies
import
Body
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_event
import
UrsinaEvent
ours_cosmic_bg
=
"
bg_pan
.jpg"
ours_cosmic_bg
=
"
cosmic_pan_1
.jpg"
worms_cosmic_bg
=
"
bg_pan_red
.jpg"
worms_cosmic_bg
=
"
cosmic_pan_4
.jpg"
class
UniverseBody
(
Body
):
class
WormholeSim
:
def
__init__
(
self
,
name
=
"虫洞"
,
mass
=
1.9891e35
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
color
=
(
0
,
0
,
0
),
texture
=
None
,
density
=
1.408e20
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
rotation_speed
=
0
,
ignore_mass
=
False
,
trail_color
=
None
,
show_name
=
False
):
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
density
,
"color"
:
color
,
"texture"
:
texture
,
"size_scale"
:
size_scale
*
10000
,
"distance_scale"
:
distance_scale
,
"rotation_speed"
:
rotation_speed
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"show_name"
:
show_name
}
super
().
__init__
(
**
params
)
class
WormHole
(
UniverseBody
):
def
__init__
(
self
,
name
=
"虫洞"
,
mass
=
1.9891e35
,
texture
=
worms_cosmic_bg
,
size_scale
=
1.0
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]):
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
1.408e20
,
# "color": color,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
# "distance_scale": distance_scale,
# "rotation_speed": rotation_speed,
# "ignore_mass": ignore_mass,
# "trail_color": trail_color,
# "show_name": show_name
}
super
().
__init__
(
**
params
)
class
OursUniverse
(
UniverseBody
):
def
__init__
(
self
,
name
=
"我们的宇宙"
,
texture
=
ours_cosmic_bg
,
size_scale
=
1.0
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
]):
params
=
{
"name"
:
name
,
"mass"
:
1.9891e35
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
1.408e20
,
# "color": color,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
# "distance_scale": distance_scale,
# "ignore_mass": ignore_mass,
# "trail_color": trail_color,
# "show_name": show_name
}
super
().
__init__
(
**
params
)
if
__name__
==
'__main__'
:
"""
"""
# 代码案例如下:
SIZE_SCALE
=
1
# 生成的太阳放大 50 倍
SIZE_SCALE
=
1
# 生成的太阳放大 50 倍
RUN_DIAMETER
=
1.392e6
RUN_DIAMETER
=
1.392e6
velocity_rate
=
22
velocity_rate
=
22
camera_target
=
CoreValagaClas
(
name
=
"摄像机目标"
,
mass
=
1e30
,
color
=
(
111
,
140
,
255
),
def
__init__
(
self
):
self
.
camera_target
=
CoreValagaClas
(
name
=
"摄像机目标"
,
mass
=
1e30
,
color
=
(
111
,
140
,
255
),
# init_position=[0, 0, 0],
# init_position=[0, 0, 0],
init_position
=
[
0
,
0
,
AU
/
10
],
init_position
=
[
0
,
0
,
AU
/
10
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
SIZE_SCALE
*
1e1
)
# .set_ignore_gravity(True)
size_scale
=
WormholeSim
.
SIZE_SCALE
*
1e1
)
# .set_ignore_gravity(True)
ours_universe
=
OursUniverse
(
self
.
universes
=
[]
# size_scale=SIZE_SCALE * 1e3,
size_scale
=
SIZE_SCALE
,
self
.
ours_universe
=
create_universe_body
(
"我们的宇宙"
,
"cosmic_pan_1.jpg"
,
init_position
=
[
0
,
0
,
-
AU
/
120
],
size_scale
=
WormholeSim
.
SIZE_SCALE
,
init_position
=
[
0
,
0
,
-
AU
/
120
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
).
set_ignore_gravity
(
True
)
)
worm_hole
=
WormHole
(
self
.
universes
.
append
(
self
.
ours_universe
)
# init_position=[RUN_DIAMETER, RUN_DIAMETER, 0]
,
self
.
worm_hole
=
create_universe_body
(
"虫洞1"
,
"cosmic_pan_4.jpg"
,
init_position
=
[
0
,
0
,
AU
/
120
],
init_position
=
[
0
,
0
,
AU
/
120
],
init_velocity
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
size_scale
=
SIZE_SCALE
).
set_ignore_gravity
(
True
)
size_scale
=
WormholeSim
.
SIZE_SCALE
)
bodies
=
[
self
.
universes
.
append
(
self
.
worm_hole
)
camera_target
,
self
.
bodies
=
[
self
.
camera_target
]
+
self
.
universes
ours_universe
,
worm_hole
]
# camera_position = [0, 0, 0]
def
on_ready
():
def
on_ready
(
self
):
"""
"""
事件绑定后,模拟器运行前会触发
事件绑定后,模拟器运行前会触发
@return:
@return:
...
@@ -135,29 +59,30 @@ if __name__ == '__main__':
...
@@ -135,29 +59,30 @@ if __name__ == '__main__':
# camera.scale = 1000
# camera.scale = 1000
# camera.parent = camera_target.planet
# camera.parent = camera_target.planet
# camera.rotation_x = 90
# camera.rotation_x = 90
camera
.
fov
=
120
worm_hole
.
planet
.
rotation_y
=
30
self
.
worm_hole
.
planet
.
rotation_y
=
30
ours_universe
.
planet
.
rotation_y
=
130
self
.
ours_universe
.
planet
.
rotation_y
=
130
camera_look_at
(
camera_target
)
camera_look_at
(
self
.
camera_target
)
camera
.
collider
=
"sphere"
camera
.
collider
=
"sphere"
worm_hole
.
planet
.
collider
=
"sphere"
self
.
worm_hole
.
planet
.
collider
=
"sphere"
ours_universe
.
planet
.
init_scale
=
SIZE_SCALE
*
1000
self
.
ours_universe
.
planet
.
init_scale
=
self
.
SIZE_SCALE
*
1000
self
.
camera_target
.
current_universe
=
self
.
ours_universe
self
.
camera_target
.
targe_universe
=
self
.
worm_hole
# camera_position = camera.position
# camera_position = camera.position
def
on_timer_changed
(
self
,
time_data
):
def
on_timer_changed
(
time_data
):
global
camera_position
# return
# return
# pass
# pass
# camera_look_at(camera_target)
# camera_look_at(camera_target)
# camera.rotation_x -= 2
# camera.rotation_x -= 2
camera_target
.
planet
.
look_at
(
worm_hol
e
.
planet
)
self
.
camera_target
.
planet
.
look_at
(
self
.
camera_target
.
targe_univers
e
.
planet
)
if
camera
.
intersects
(
worm_hol
e
.
planet
).
hit
:
if
camera
.
intersects
(
self
.
camera_target
.
targe_univers
e
.
planet
).
hit
:
# worm_hole.planet.init_scale = SIZE_SCALE * 1000
# worm_hole.planet.init_scale = SIZE_SCALE * 1000
ours_universe
.
planet
.
init_scale
=
SIZE_SCALE
self
.
camera_target
.
current_universe
.
planet
.
init_scale
=
self
.
SIZE_SCALE
if
worm_hole
.
planet
.
init_scale
<
SIZE_SCALE
*
1000
:
if
self
.
camera_target
.
targe_universe
.
planet
.
init_scale
<
self
.
SIZE_SCALE
*
1000
:
worm_hol
e
.
planet
.
init_scale
*=
1.1
self
.
camera_target
.
targe_univers
e
.
planet
.
init_scale
*=
1.1
# if ours_universe.planet.init_scale > SIZE_SCALE:
# if ours_universe.planet.init_scale > SIZE_SCALE:
# ours_universe.planet.init_scale /= 1.1
# ours_universe.planet.init_scale /= 1.1
if
not
hasattr
(
camera
,
"init_rotation_y"
):
if
not
hasattr
(
camera
,
"init_rotation_y"
):
...
@@ -165,11 +90,11 @@ if __name__ == '__main__':
...
@@ -165,11 +90,11 @@ if __name__ == '__main__':
camera
.
rotation_y_v
=
0.01
camera
.
rotation_y_v
=
0.01
if
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
10
:
if
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
10
:
camera
.
rotation_y_v
+=
0.
00
5
camera
.
rotation_y_v
+=
0.5
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
90
:
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
90
:
camera
.
rotation_y_v
+=
0.
01
camera
.
rotation_y_v
+=
0.
3
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
120
:
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
120
:
camera
.
rotation_y_v
-=
0.
0
1
camera
.
rotation_y_v
-=
0.1
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
180
:
elif
abs
(
camera
.
init_rotation_y
-
camera
.
rotation_y
)
<
180
:
camera
.
rotation_y_v
-=
0.01
camera
.
rotation_y_v
-=
0.01
if
camera
.
rotation_y_v
<
0.1
:
if
camera
.
rotation_y_v
<
0.1
:
...
@@ -185,27 +110,37 @@ if __name__ == '__main__':
...
@@ -185,27 +110,37 @@ if __name__ == '__main__':
# camera_target.planet.position = lerp(camera_target.planet.position, worm_hole.planet.position, 1e-2)
# camera_target.planet.position = lerp(camera_target.planet.position, worm_hole.planet.position, 1e-2)
# print(2,camera_target.planet.position)
# print(2,camera_target.planet.position)
# camera.position = (camera.position[0],camera.position[1],camera.position[2]) #
# camera.position = (camera.position[0],camera.position[1],camera.position[2]) #
camera
.
position
=
lerp
(
camera
.
position
,
camera_target
.
planet
.
position
,
0.3
e-2
)
camera
.
position
=
lerp
(
camera
.
position
,
self
.
camera_target
.
planet
.
position
,
0.2
e-2
)
# camera_position = [camera_position[0], camera_position[1], camera_position[2] - 0.01]
# camera_position = [camera_position[0], camera_position[1], camera_position[2] - 0.01]
# camera.position = camera_position
# camera.position = camera_position
def
build_events
(
self
):
# 订阅事件后,上面2个函数功能才会起作用
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
UrsinaEvent
.
on_timer_changed_subscription
(
wormhole_sim
.
on_timer_changed
)
# 运行前会触发 on_ready
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_ready_subscription
(
wormhole_sim
.
on_ready
)
def
run
(
self
):
self
.
build_events
()
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_DAY
/
24
,
ursina_run
(
self
.
bodies
,
SECONDS_PER_DAY
/
24
,
# position=(0, AU / 1200, -1.003 * AU),
# position=(0, AU / 1200, -1.003 * AU),
# position=[-AU/100, 0, 0],
# position=[-AU/100, 0, 0],
position
=
[
0
,
0
,
-
AU
/
10
],
position
=
[
0
,
0
,
-
AU
/
10
],
cosmic_bg
=
''
,
cosmic_bg
=
''
,
# gravity_works=False,
# gravity_works=False,
timer_enabled
=
True
,
timer_enabled
=
True
,
show_grid
=
False
,
show_grid
=
False
,
show_trail
=
False
)
show_trail
=
False
)
if
__name__
==
'__main__'
:
"""
"""
wormhole_sim
=
WormholeSim
()
wormhole_sim
.
run
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录