Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
fc8c8bda
宇宙模拟器
项目概览
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看板
提交
fc8c8bda
编写于
10月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
a8146b83
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
149 addition
and
2 deletion
+149
-2
objs/__init__.py
objs/__init__.py
+1
-0
objs/obj.py
objs/obj.py
+8
-2
objs/quad_obj.py
objs/quad_obj.py
+48
-0
sim_scenes/tri_bodies/two_way_foil.py
sim_scenes/tri_bodies/two_way_foil.py
+92
-0
未找到文件。
objs/__init__.py
浏览文件 @
fc8c8bda
from
objs.obj
import
Obj
from
objs.diamond
import
Diamond
from
objs.quad_obj
import
QuadObj
from
objs.football
import
Football
from
objs.satellite
import
Satellite
,
Satellite2
from
objs.space_ship
import
SpaceShip
...
...
objs/obj.py
浏览文件 @
fc8c8bda
...
...
@@ -51,7 +51,10 @@ class Obj(metaclass=ABCMeta):
self
.
__his_acc
=
[]
self
.
__his_reserved_num
=
200
self
.
gravity_only_for
=
gravity_only_for
self
.
model
=
self
.
find_model
(
model
)
if
isinstance
(
model
,
str
):
self
.
model
=
self
.
find_model
(
model
)
else
:
self
.
model
=
model
self
.
rotation
=
rotation
if
name
is
None
:
...
...
@@ -350,7 +353,9 @@ class Obj(metaclass=ABCMeta):
def
__repr__
(
self
):
return
'<%s(%s):%s(%s)> m=%.3e(kg), d=%.3e(kg/m³), p=[%.3e,%.3e,%.3e](km), v=%s(km/s), s=%.3e'
%
\
(
self
.
name
,
self
.
__class__
.
__name__
,
os
.
path
.
basename
(
self
.
model
),
os
.
path
.
basename
(
self
.
texture
),
(
self
.
name
,
self
.
__class__
.
__name__
,
os
.
path
.
basename
(
self
.
model
)
if
isinstance
(
self
.
model
,
str
)
else
self
.
model
,
os
.
path
.
basename
(
self
.
texture
)
if
isinstance
(
self
.
texture
,
str
)
else
self
.
texture
,
self
.
mass
,
self
.
density
,
self
.
position
[
0
],
self
.
position
[
1
],
self
.
position
[
2
],
self
.
velocity
,
self
.
size_scale
)
...
...
@@ -485,6 +490,7 @@ class Obj(metaclass=ABCMeta):
self
.
size_scale
=
size_scale
# self.init_position = np.array([0, -3000000, 9000000])
self
.
init_position
=
np
.
array
([
0
,
0
,
0
])
def
on_ready
():
camera_look_at
(
self
)
if
callable
(
on_ready_fun
):
...
...
objs/quad_obj.py
0 → 100644
浏览文件 @
fc8c8bda
# -*- coding:utf-8 -*-
# title :四边形
# description :四边形
# author :Python超人
# date :2023-10-11
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
from
objs.obj
import
Obj
class
QuadObj
(
Obj
):
"""
四边形
密度:3.51g/cm³
"""
def
__init__
(
self
,
name
=
"四边形"
,
mass
=
5.97237e24
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
0
,
0
],
texture
=
None
,
size_scale
=
1.0
,
distance_scale
=
1.0
,
ignore_mass
=
False
,
density
=
3.51e3
,
color
=
(
7
,
0
,
162
),
trail_color
=
None
,
show_name
=
False
,
parent
=
None
,
gravity_only_for
=
[]):
from
ursina.models.procedural.quad
import
Quad
params
=
{
"name"
:
name
,
"mass"
:
mass
,
"init_position"
:
init_position
,
"init_velocity"
:
init_velocity
,
"density"
:
density
,
"color"
:
color
,
"texture"
:
texture
,
"size_scale"
:
size_scale
,
"distance_scale"
:
distance_scale
,
"ignore_mass"
:
ignore_mass
,
"trail_color"
:
trail_color
,
"show_name"
:
show_name
,
"parent"
:
parent
,
"gravity_only_for"
:
gravity_only_for
,
"model"
:
Quad
(
0
),
}
super
().
__init__
(
**
params
)
if
__name__
==
'__main__'
:
quad
=
QuadObj
()
print
(
quad
)
sim_scenes/tri_bodies/two_way_foil.py
0 → 100644
浏览文件 @
fc8c8bda
# -*- coding:utf-8 -*-
# title :三体二向箔场景模拟
# description :三体二向箔场景模拟
# author :Python超人
# date :2023-10-11
# link :https://gitcode.net/pythoncr/
# python_version :3.9
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
from
objs
import
CoreValagaClas
,
SciFiBomber
,
WaterDrop
,
QuadObj
from
common.consts
import
AU
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
,
SECONDS_PER_MONTH
from
sim_scenes.func
import
ursina_run
,
camera_look_at
,
create_main_entity
,
two_bodies_colliding
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.entities.entity_utils
import
create_directional_light
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
camera
if
__name__
==
'__main__'
:
"""
三体二向箔场景模拟
"""
from
bodies
import
Sun
,
Mercury
,
Venus
,
Earth
,
Mars
,
Jupiter
,
Saturn
,
Uranus
,
Neptune
,
Pluto
,
Asteroids
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
simulators.ursina.ursina_event
import
UrsinaEvent
if
__name__
==
'__main__'
:
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
# 排列顺序
# 1、体积:(以地球为1)木星 :土星 :天王星 :海王星 :地球 :金星 :火星 :水星 = 1330:745:65:60:1:0.86:0.15:0.056
# 2、质量:(以地球为1)木星 :土星 :天王星 :海王星 :地球 :金星 :火星 :水星 = 318:95:14.53:17.15:1:0.8:0.11:0.0553
# 3、离太阳从近到远的顺序:水星、金星、地球、火星、木星、土星、天王星、海王星
# =====================================================================
# 以下展示的效果非太阳系真实的距离和大小
# 1、由于宇宙空间尺度非常大,如果按照实际的天体大小,则无法看到天体,因此需要对天体的尺寸进行放大
# 2、为了达到最佳的显示效果,对每个行星天体的距离进行了缩放
# region 构建太阳系
sun
=
Sun
(
size_scale
=
0.8e2
)
bodies
=
[
sun
,
# 太阳放大 80 倍
Mercury
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 水星放大 4000 倍,距离放大 1.3 倍
Venus
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 金星放大 4000 倍,距离放大 1.3 倍
Earth
(
size_scale
=
4e3
,
distance_scale
=
1.3
),
# 地球放大 4000 倍,距离放大 1.3 倍
Mars
(
size_scale
=
4e3
,
distance_scale
=
1.2
),
# 火星放大 4000 倍,距离放大 1.2 倍
Asteroids
(
size_scale
=
1e2
,
parent
=
sun
),
# 小行星模拟(仅 ursina 模拟器支持)
Jupiter
(
size_scale
=
0.68e3
,
distance_scale
=
0.72
),
# 木星放大 680 倍,距离缩小到真实距离的 0.72
Saturn
(
size_scale
=
0.68e3
,
distance_scale
=
0.52
),
# 土星放大 680 倍,距离缩小到真实距离的 0.52
Uranus
(
size_scale
=
0.8e3
,
distance_scale
=
0.36
),
# 天王星放大 800 倍,距离缩小到真实距离的 0.36
Neptune
(
size_scale
=
1e3
,
distance_scale
=
0.27
),
# 海王星放大 1000 倍,距离缩小到真实距离的 0.27
Pluto
(
size_scale
=
10e3
,
distance_scale
=
0.23
),
# 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除)
]
# endregion
two_way_foil
=
QuadObj
(
texture
=
'caustic.jpg'
,
size_scale
=
2e8
,
init_velocity
=
[
-
10
,
-
10
,
0
],
init_position
=
[
0
,
0
,
39.55
*
AU
])
\
.
set_light_disable
(
True
).
set_ignore_gravity
(
True
)
bodies
.
append
(
two_way_foil
)
def
on_ready
():
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 创建天空
create_sphere_sky
(
scale
=
8000
)
def
on_timer_changed
(
time_data
):
two_way_foil
.
planet
.
rotation_x
+=
1
two_way_foil
.
planet
.
rotation_y
+=
2
pass
# 订阅事件后,上面2个函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_MONTH
,
position
=
(
0
,
2
*
AU
,
-
11
*
AU
),
cosmic_bg
=
''
,
timer_enabled
=
True
,
show_grid
=
False
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录