Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
309f55b8
宇宙模拟器
项目概览
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看板
提交
309f55b8
编写于
3月 27, 2024
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
63b6c9c3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
16 deletion
+71
-16
sim_scenes/featured/tri_bodies_01.py
sim_scenes/featured/tri_bodies_01.py
+71
-16
未找到文件。
sim_scenes/featured/tri_bodies_01.py
浏览文件 @
309f55b8
...
...
@@ -10,9 +10,10 @@ from bodies import Sun, Earth
from
common.consts
import
SECONDS_PER_WEEK
,
SECONDS_PER_YEAR
,
SECONDS_PER_MONTH
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
create_sphere_sky
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ui.control_ui
import
ControlUI
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
ursina
import
application
,
window
,
camera
,
EditorCamera
from
ursina
import
application
,
window
,
camera
,
EditorCamera
,
Text
,
color
import
numpy
as
np
from
simulators.ursina_simulator
import
UrsinaSimulator
...
...
@@ -25,38 +26,85 @@ if __name__ == '__main__':
2、三个方向的初始速度 init_velocity[x, y, z]
3、天体质量 mass
"""
# glows = (glow_num:10, glow_scale:1.03 glow_alpha:0.1~1)
sun_glows
=
(
4
,
1.01
,
0.01
)
sun1
=
Sun
(
mass
=
1.55e30
,
init_position
=
[
8.5e8
,
0
,
1000000
],
init_velocity
=
[
0.0
,
7.1
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
0
,
255
,
0
))
# sun1.glows = (12, 1.015, 0.08)
sun1
.
glows
=
sun_glows
sun2
=
Sun
(
mass
=
2.1e30
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
-
8.0
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
255
,
255
,
0
))
sun2
.
glows
=
sun_glows
sun3
=
Sun
(
mass
=
2.5e30
,
init_position
=
[
0
,
-
8.5e8
,
-
2000000
],
init_velocity
=
[
12.0
,
0
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
255
,
120
,
120
))
sun3
.
glows
=
sun_glows
earth
=
Earth
(
init_position
=
[
0
,
-
3.5e8
,
3000000
],
init_velocity
=
[
13.360
,
0
,
0
],
rotate_angle
=
0
,
size_scale
=
4e3
,
distance_scale
=
1
,
trail_color
=
(
120
,
160
,
255
))
bodies
=
[
Sun
(
mass
=
1.55e30
,
init_position
=
[
8.5e8
,
0
,
1000000
],
init_velocity
=
[
0.0
,
7.1
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
111
,
140
,
255
)),
# 蓝色太阳
Sun
(
mass
=
2.1e30
,
init_position
=
[
0
,
0
,
0
],
init_velocity
=
[
0
,
-
8.0
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
250
,
195
,
47
)),
# 红色太阳
Sun
(
mass
=
2.5e30
,
init_position
=
[
0
,
-
8.5e8
,
-
2000000
],
init_velocity
=
[
12.0
,
0
,
0
],
size_scale
=
5e1
,
texture
=
"sun21.jpg"
,
color
=
(
198
,
29
,
3
)),
# 黄色太阳
Earth
(
init_position
=
[
0
,
-
3.5e8
,
3000000
],
init_velocity
=
[
13.360
,
0
,
0
],
rotate_angle
=
0
,
size_scale
=
4e3
,
distance_scale
=
1
),
# 地球放大 4000 倍,距离保持不变
sun1
,
# 绿色太阳
sun2
,
# 黄色太阳
sun3
,
# 红色太阳
earth
,
# 地球放大 4000 倍,距离保持不变
]
sky
=
None
# 使用 mayavi 查看的运行效果
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=0)
def
on_ready
():
from
ursina
import
Text
,
color
window
.
borderless
=
False
global
sky
window
.
borderless
=
True
window
.
exit_button
=
False
# window.fullscreen = True
window
.
position
=
(
1920
,
0
)
# 设置窗口的宽度和高度
window
.
size
=
(
2340
,
1079
)
sky
=
create_sphere_sky
(
scale
=
80000
,
texture
=
"bg_pan_deep_blue.jpg"
)
camera
.
clip_plane_near
=
1
camera
.
clip_plane_far
=
sky
.
scale_x
*
1.5
show_title
()
def
show_title
():
font
=
"fonts/DroidSansFallback.ttf"
from
common.func
import
find_file
font
=
find_file
(
f
"
{
font
}
"
,
UrsinaConfig
.
CN_FONT
)
text
=
Text
(
text
=
"万有引力模拟三体"
,
color
=
color
.
white
,
scale
=
1.5
,
position
=
(
-
0.85
,
0.48
),
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
-
0.5
*
aspect_ratio
+
0.15
,
0.48
),
(
-
0.05
,
0.1
),
text
=
Text
(
text
=
"三体模拟"
,
color
=
color
.
white
,
scale
=
1.5
,
position
=
position
,
# (-0.98, 0.48),
font
=
font
)
def
show_clock
(
dt
):
"""
显示时钟
@param dt: 时间 datetime
@return:
"""
# if self.clock_position_center:
# position, origin = (0, .25), (0, 0),
# else:
from
ursina
import
window
aspect_ratio
=
window
.
aspect_ratio
position
,
origin
=
(
0.
,
0.48
),
(
0.15
,
0.1
),
ControlUI
.
current_ui
.
show_message
(
dt
.
strftime
(
'%Y-%m-%d'
),
position
=
position
,
origin
=
origin
,
# font="verdana.ttf",
font
=
"fonts/Digital-7Mono.TTF"
,
font_scale
=
2
,
font_color
=
(
0
,
255
,
0
),
close_time
=-
1
)
def
on_timer_changed
(
time_data
:
TimeData
):
global
sky
sky
.
rotation_y
-=
0.01
total_days
=
time_data
.
total_days
ec
=
UrsinaSimulator
.
EditorCamera
print
(
total_days
)
#
print(total_days)
if
100
<
total_days
<
3000
:
camera
.
position
+=
camera
.
right
*
0.1
camera
.
position
+=
camera
.
down
*
0.02
...
...
@@ -77,6 +125,9 @@ if __name__ == '__main__':
# elif total_days > 3500:
# camera.position += camera.back * 0.1
dt
=
time_data
.
get_datetime
(
start_time
)
show_clock
(
dt
)
def
on_reset
():
reset_camera
()
...
...
@@ -92,12 +143,16 @@ if __name__ == '__main__':
ec
.
target_z
=
ec
.
original_target_z
camera
.
position
=
camera
.
original_position
start_time
=
'2024-01-01 00:00:00'
UrsinaConfig
.
trail_type
=
"line"
# UrsinaConfig.trail_length = 91
#
UrsinaConfig.trail_type = "curve_line"
UrsinaConfig
.
trail_type
=
"curve_line"
UrsinaConfig
.
trail_length
=
50
# UrsinaConfig.trail_length = 1000
UrsinaConfig
.
trail_thickness_factor
=
2
UrsinaConfig
.
trail_thickness_factor
=
5
# UrsinaConfig.trail_factor = 10
# 运行前会触发 on_ready
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# 运行中,每时每刻都会触发 on_timer_changed
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录