Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
c9bec893
宇宙模拟器
项目概览
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看板
提交
c9bec893
编写于
8月 02, 2024
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
62ca2e93
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
5 deletion
+86
-5
bodies/fixed_stars/fixed_star.py
bodies/fixed_stars/fixed_star.py
+3
-3
sim_scenes/funny/china_earth.py
sim_scenes/funny/china_earth.py
+81
-0
sim_scenes/funny/utils/body_utils.py
sim_scenes/funny/utils/body_utils.py
+2
-2
未找到文件。
bodies/fixed_stars/fixed_star.py
浏览文件 @
c9bec893
...
...
@@ -74,9 +74,9 @@ class FixedStar(Body):
# save_file = os.path.join(temp_dir, "%s_%s.png" % (texture_name, "_".join([str(i) for i in list(self.color)])))
save_file
=
os
.
path
.
join
(
temp_dir
,
"%s_%s.png"
%
(
texture_name
,
str
(
self
.
__class__
.
__name__
).
lower
()))
if
os
.
path
.
exists
(
save_file
):
return
save_file
if
self
.
__class__
is
not
FixedStar
:
if
os
.
path
.
exists
(
save_file
):
return
save_file
fixed_star_img
=
os
.
path
.
join
(
texture_path
,
texture
)
gen_fixed_star_texture
(
self
.
color
,
...
...
sim_scenes/funny/china_earth.py
0 → 100644
浏览文件 @
c9bec893
# -*- coding:utf-8 -*-
# title :组成文本的星球群(自定义星球)
# description :组成文本的星球群(自定义星球)
# author :Python超人
# date :2023-03-26
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
FixedStar
,
ColorBody
,
Earth
,
Sun
from
common.consts
import
SECONDS_PER_HOUR
,
SECONDS_PER_DAY
,
SECONDS_PER_WEEK
from
sim_scenes.func
import
ursina_run
,
create_sphere_sky
from
sim_scenes.funny.utils.body_utils
import
gen_bodies_from_image
from
simulators.ursina.ursina_event
import
UrsinaEvent
D
=
6000
# 基本距离单位:km(随意赋值)
def
create_earth
(
name
,
texture
,
scale
):
earth
=
Earth
(
name
=
name
,
texture
=
texture
,
rotate_angle
=-
23.44
,
mass
=
2e32
,
size_scale
=
5
*
scale
,
init_position
=
[
-
450
*
D
,
100
*
D
,
6000
*
D
],
# [ 左-右+, 上+下-, 远+近- ]
init_velocity
=
[
0
,
0
,
0
],
ignore_mass
=
True
)
return
earth
def
show_text_bodies
():
"""
显示图片文本的星球群
"""
# 观看摄像机的位置
# camera_pos = (左-右+, 上+下-, 前+后-)
camera_pos
=
(
D
,
D
,
-
3000
*
D
)
# 根据 pixel_image 指定图片生成有色星球(注意:图片的像素不要太多)
bodies
=
gen_bodies_from_image
(
pixel_image
=
"./images/ilovechina.png"
,
texture
=
"color_moon.png"
,
params
=
{
"camera_pos"
:
camera_pos
},
light_disable
=
False
)
# 放一个恒星作为背景
# TODO: ignore_mass=True
# 注意:这里的算法是基于牛顿的万有引力(质量为0不受引力的影响在天体物理学中是不严谨)
sun
=
FixedStar
(
init_position
=
[
camera_pos
[
0
],
camera_pos
[
1
],
camera_pos
[
2
]
*
30
],
texture
=
"fixed_star.png"
,
color
=
(
255
,
255
,
225
),
size_scale
=
20
)
# glows = (glow_num:10, glow_scale:1.03 glow_alpha:0.1~1 glow_color_min_val)
sun
.
glows
=
(
10
,
1.05
,
0.1
)
bodies
.
append
(
sun
)
earth
=
create_earth
(
name
=
"背景地球"
,
texture
=
"earth-huge.jpg"
,
scale
=
1
)
earth_cn
=
create_earth
(
name
=
"背景地球"
,
texture
=
"earth-huge-cn-flag.png"
,
scale
=
1.01
)
earth_clouds
=
create_earth
(
name
=
"地球云层"
,
texture
=
"transparent_clouds.png"
,
scale
=
1.005
)
bodies
.
append
(
earth
)
bodies
.
append
(
earth_cn
)
bodies
.
append
(
earth_clouds
)
def
on_ready
():
# from simulators.ursina.entities.entity_utils import create_directional_light
# # 运行前触发
# # 为了较好的立体效果,可以增加太阳光线,光线指向木星(target=jupiter)
# create_directional_light(position=(200, 0, -300), light_num=3, target=earth)
from
ursina
import
camera
# camera.fov = 40
sky
=
create_sphere_sky
(
scale
=
800000
)
sky
.
rotation_y
=
180
# sky.rotation_x = 20
# sky.rotation_z = -65
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = camera_pos = (左-右+, 上+下-, 前+后-)
ursina_run
(
bodies
,
SECONDS_PER_HOUR
,
cosmic_bg
=
''
,
show_grid
=
False
,
position
=
camera_pos
,
view_closely
=
True
)
if
__name__
==
'__main__'
:
show_text_bodies
()
sim_scenes/funny/utils/body_utils.py
浏览文件 @
c9bec893
...
...
@@ -29,7 +29,7 @@ def get_scaled_body_pos(camera_pos, body_pos, scale_factor):
return
new_pos
def
gen_bodies_from_image
(
pixel_image
,
params
,
texture
=
"color_body.png"
):
def
gen_bodies_from_image
(
pixel_image
,
params
,
texture
=
"color_body.png"
,
light_disable
=
True
):
"""
根据像素图片以及参数,自动生成星球,注意图片像素不能太多,否则会导致电脑运行太慢
@param pixel_image:
...
...
@@ -63,7 +63,7 @@ def gen_bodies_from_image(pixel_image, params, texture="color_body.png"):
interval_factor
=
20
# 星球间距因子
body_template
=
'ColorBody(name="%s", mass=mass, color=(%d, %d, %d), size_scale=%.4f, '
\
'init_position=get_position([-%g * D, %g * D, 0], %.4f), '
\
f
'init_velocity=[0, 0, 0], ignore_mass=True, texture="
{
texture
}
").set_light_disable(
True
)'
f
'init_velocity=[0, 0, 0], ignore_mass=True, texture="
{
texture
}
").set_light_disable(
{
light_disable
}
)'
bodies_str
=
"["
# 以图片像素为坐标,对角线的距离
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录