Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
d41c662f
宇宙模拟器
项目概览
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看板
提交
d41c662f
编写于
3月 26, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
925eb2df
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
170 addition
and
3 deletion
+170
-3
sim_scenes/interest/__init__.py
sim_scenes/interest/__init__.py
+0
-0
sim_scenes/interest/images/eye.png
sim_scenes/interest/images/eye.png
+0
-0
sim_scenes/interest/the_eye_of_god.py
sim_scenes/interest/the_eye_of_god.py
+86
-0
sim_scenes/interest/utils/__init__.py
sim_scenes/interest/utils/__init__.py
+0
-0
sim_scenes/interest/utils/body_utils.py
sim_scenes/interest/utils/body_utils.py
+77
-0
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+7
-3
未找到文件。
sim_scenes/interest/__init__.py
0 → 100644
浏览文件 @
d41c662f
sim_scenes/interest/images/eye.png
0 → 100644
浏览文件 @
d41c662f
3.1 KB
sim_scenes/interest/the_eye_of_god.py
0 → 100644
浏览文件 @
d41c662f
# -*- coding:utf-8 -*-
# title :上帝之眼
# description :上帝之眼
# author :Python超人
# date :2023-03-26
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Moon
,
FixedStar
,
Body
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_HALF_DAY
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
bodies.body
import
AU
import
random
def
show_eye_of_god
():
"""
上帝之眼
"""
D
=
600
mass
=
0.9e25
# camera_pos = 左-右+、上+下-、前+后-
camera_pos
=
(
-
100
*
D
,
0
,
-
5000
*
D
)
def
get_position
(
pos
,
scale
):
# [ 远+近- , 左+右- , 上+下-]
return
pos
[
0
]
+
(
scale
-
1.0
)
*
300
*
(
random
.
randint
(
90
,
110
))
*
D
,
pos
[
1
],
pos
[
2
]
# return pos[0], pos[1], pos[2]
bodies
:
list
=
gen_eye_bodies
(
{
"D"
:
D
,
"Body"
:
Body
,
"mass"
:
mass
,
"get_position"
:
get_position
,
"camera_pos"
:
camera_pos
})
face
=
FixedStar
(
name
=
"face"
,
texture
=
"fixed_star.png"
,
mass
=
mass
*
3000
,
color
=
(
0xff
,
0xf8
,
0xd4
),
init_position
=
[
2000
*
D
,
240
*
D
,
-
90
*
D
],
# [ 远+近- , 左+右- , 上+下-]
ignore_mass
=
True
)
face
.
light_on
=
False
bodies
.
append
(
face
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_WEEK
*
2
,
position
=
camera_pos
)
def
gen_eye_bodies
(
params
):
"""
根据像素图片以及参数,自动生成星球,注意图片像素不能太多,否则会导致电脑运行太慢
@param params:
@return:
"""
from
PIL
import
Image
img
=
Image
.
open
(
"./images/eye.png"
).
convert
(
'RGBA'
)
width
,
height
=
img
.
size
interval_factor
=
20
# 星球间距因子
body_template
=
'Body(name="%s", mass=mass, color=(%d, %d, %d), size_scale=%.4f, '
\
'init_position=get_position([0, %g * D, %g * D], %.4f), init_velocity=[0, 0, 0], ignore_mass=True)'
bodies_str
=
"["
# 以图片像素为坐标,对角线的距离
distance_hw
=
pow
(
pow
(
width
,
2
)
+
pow
(
height
,
2
),
1
/
2
)
for
h
in
range
(
0
,
height
):
# row = []
for
w
in
range
(
0
,
width
):
# 以图片像素为坐标,每个像素点到中心的距离
distance_to_center
=
pow
(
pow
(
w
-
width
/
2
,
2
)
+
pow
(
h
-
height
/
2
,
2
),
1
/
2
)
# 让 body 从中心开始,离摄像机越远, body 的缩放值越大(scale 就越大,)
scale
=
(
distance_to_center
/
(
distance_hw
*
10
)
+
1
)
# 中心最近 1.0 ~ 1.05
# TODO: 队列反向排列(中心最远 1.05 ~ 1.0)
# scale = 1.05 - scale + 1.0
# print(scale)
# 获取像素的颜色
pixel
=
img
.
getpixel
((
w
,
h
))
# 对于纯白色的颜色,就忽略,不生成星球(这样像素中纯白色越多,对电脑的压力就越少)
if
pixel
[
0
]
>=
255
and
pixel
[
1
]
>=
255
and
pixel
[
1
]
>=
255
:
continue
body_str
=
body_template
%
(
f
"星球
{
h
}
:
{
w
}
"
,
pixel
[
0
],
pixel
[
1
],
pixel
[
2
],
scale
,
w
*
interval_factor
,
-
h
*
interval_factor
,
scale
)
bodies_str
+=
body_str
+
",
\n
"
bodies_str
+=
"]"
return
eval
(
bodies_str
,
params
)
if
__name__
==
'__main__'
:
show_eye_of_god
()
sim_scenes/interest/utils/__init__.py
0 → 100644
浏览文件 @
d41c662f
sim_scenes/interest/utils/body_utils.py
0 → 100644
浏览文件 @
d41c662f
# -*- coding:utf-8 -*-
# title :Body工具类
# description :Body工具类
# author :Python超人
# date :2023-03-26
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
def
gen_eye_bodies
(
pixel_image
,
params
,
body_template
=
None
):
"""
根据像素图片以及参数,自动生成星球,注意图片像素不能太多,否则会导致电脑运行太慢
@param pixel_image:
@param params:
@return:
"""
from
PIL
import
Image
img
=
Image
.
open
(
pixel_image
).
convert
(
'RGBA'
)
width
,
height
=
img
.
size
interval_factor
=
20
# 星球间距因子
if
body_template
is
None
:
body_template
=
'Body(name="%s", mass=mass, color=(%d, %d, %d), size_scale=%.4f, '
\
'init_position=get_position([0, %g * D, %g * D], %.4f), init_velocity=[0, 0, 0], ignore_mass=True)'
bodies_str
=
"["
# 以图片像素为坐标,对角线的距离
distance_hw
=
pow
(
pow
(
width
,
2
)
+
pow
(
height
,
2
),
1
/
2
)
for
h
in
range
(
0
,
height
):
# row = []
for
w
in
range
(
0
,
width
):
# 以图片像素为坐标,每个像素点到中心的距离
distance_to_center
=
pow
(
pow
(
w
-
width
/
2
,
2
)
+
pow
(
h
-
height
/
2
,
2
),
1
/
2
)
# 让 body 从中心开始,离摄像机越远, body 的缩放值越大(scale 就越大,)
scale
=
(
distance_to_center
/
(
distance_hw
*
10
)
+
1
)
# 中心最近 1.0 ~ 1.05
# TODO: 队列反向排列(中心最远 1.05 ~ 1.0)
# scale = 1.05 - scale + 1.0
# print(scale)
# 获取像素的颜色
pixel
=
img
.
getpixel
((
w
,
h
))
# 对于纯白色的颜色,就忽略,不生成星球(这样像素中纯白色越多,对电脑的压力就越少)
if
pixel
[
0
]
>=
255
and
pixel
[
1
]
>=
255
and
pixel
[
1
]
>=
255
:
continue
body_str
=
body_template
%
(
f
"星球
{
h
}
:
{
w
}
"
,
pixel
[
0
],
pixel
[
1
],
pixel
[
2
],
scale
,
w
*
interval_factor
,
-
h
*
interval_factor
,
scale
)
bodies_str
+=
body_str
+
",
\n
"
bodies_str
+=
"]"
return
eval
(
bodies_str
,
params
)
if
__name__
==
'__main__'
:
import
random
from
bodies
import
Body
D
=
600
mass
=
0.9e25
# camera_pos = 左-右+、上+下-、前+后-
camera_pos
=
(
-
100
*
D
,
0
,
-
5000
*
D
)
def
get_position
(
pos
,
scale
):
# [ 远+近- , 左+右- , 上+下-]
return
pos
[
0
]
+
(
scale
-
1.0
)
*
300
*
(
random
.
randint
(
90
,
110
))
*
D
,
pos
[
1
],
pos
[
2
]
# return pos[0], pos[1], pos[2]
bodies
:
list
=
gen_eye_bodies
(
pixel_image
=
"../images/eye.png"
,
params
=
{
"D"
:
D
,
"Body"
:
Body
,
"mass"
:
mass
,
"get_position"
:
get_position
,
"camera_pos"
:
camera_pos
})
print
(
bodies
)
simulators/views/ursina_view.py
浏览文件 @
d41c662f
...
@@ -95,8 +95,14 @@ class Planet(Entity):
...
@@ -95,8 +95,14 @@ class Planet(Entity):
self
.
init_scale
=
scale
self
.
init_scale
=
scale
if
hasattr
(
body_view
,
"texture"
):
if
hasattr
(
body_view
,
"texture"
):
texture
=
load_texture
(
body_view
.
texture
)
texture
=
load_texture
(
body_view
.
texture
)
# color.white
self
.
plant_color
=
color
.
white
else
:
else
:
texture
=
None
texture
=
None
b_color
=
self
.
body_view
.
color
if
len
(
b_color
)
==
3
:
b_color
=
(
b_color
[
0
],
b_color
[
1
],
b_color
[
2
],
1.0
)
self
.
plant_color
=
color
.
rgba
(
*
b_color
)
if
hasattr
(
self
.
body_view
.
body
,
"torus_stars"
):
if
hasattr
(
self
.
body_view
.
body
,
"torus_stars"
):
# 创建一个星环小天体群(主要模拟小行星群,非一个天体)
# 创建一个星环小天体群(主要模拟小行星群,非一个天体)
...
@@ -108,9 +114,7 @@ class Planet(Entity):
...
@@ -108,9 +114,7 @@ class Planet(Entity):
rotation
=
(
0
,
0
,
0
)
rotation
=
(
0
,
0
,
0
)
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
UrsinaEvent
.
on_reset_subscription
(
self
.
on_reset
)
# color.white
self
.
plant_color
=
color
.
white
# self.plant_color = color.rgba(*self.body_view.color)
super
().
__init__
(
super
().
__init__
(
# model="sphere",
# model="sphere",
model
=
model
,
model
=
model
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录