Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
宇宙模拟器
提交
3ac5f7a4
宇宙模拟器
项目概览
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看板
提交
3ac5f7a4
编写于
4月 13, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Python超人-宇宙模拟器
上级
84831096
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
125 addition
and
7 deletion
+125
-7
sim_scenes/funny/dancing_with_jupiter.py
sim_scenes/funny/dancing_with_jupiter.py
+56
-0
sim_scenes/solar_system/sun_earth_jupiter.py
sim_scenes/solar_system/sun_earth_jupiter.py
+25
-4
simulators/ursina/entities/body_timer.py
simulators/ursina/entities/body_timer.py
+4
-0
simulators/ursina/entities/entity_utils.py
simulators/ursina/entities/entity_utils.py
+4
-2
simulators/ursina/ui/control_ui.py
simulators/ursina/ui/control_ui.py
+5
-0
simulators/ursina/ursina_config.py
simulators/ursina/ursina_config.py
+2
-0
simulators/ursina/ursina_event.py
simulators/ursina/ursina_event.py
+15
-1
simulators/ursina/ursina_mesh.py
simulators/ursina/ursina_mesh.py
+12
-0
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+2
-0
未找到文件。
sim_scenes/funny/dancing_with_jupiter.py
0 → 100644
浏览文件 @
3ac5f7a4
# -*- coding:utf-8 -*-
# title :与木星跳舞
# description :与木星跳舞
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Jupiter
,
Mars
,
Venus
from
common.consts
import
SECONDS_PER_YEAR
,
SECONDS_PER_MONTH
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_mesh
import
create_line
from
ursina
import
color
if
__name__
==
'__main__'
:
"""
与木星跳舞
"""
# 选择舞者
Dancer
=
Earth
# 舞者为地球
Dancer
=
Venus
# 舞者为金星
Dancer
=
Mars
# 舞者为火星
bodies
=
[
Sun
(
size_scale
=
0.8e2
),
# 太阳放大 80 倍
Dancer
(
size_scale
=
2e3
),
# 舞者放大 2000 倍
Jupiter
(
size_scale
=
5e2
),
# 木星放大 500 倍
]
sun
,
dancer
,
jupiter
=
bodies
[
0
],
bodies
[
1
],
bodies
[
2
]
def
on_ready
():
camera_look_at
(
sun
)
UrsinaConfig
.
trail_length
=
235
UrsinaConfig
.
trail_type
=
"line"
pass
def
on_timer_changed
(
time_data
:
TimeData
):
if
int
(
time_data
.
total_days
)
%
10
==
0
:
create_line
(
from_pos
=
jupiter
.
planet
.
position
,
to_pos
=
dancer
.
planet
.
position
,
color
=
color
.
white
)
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_YEAR
,
position
=
(
0
,
20
*
AU
,
0
),
show_timer
=
True
,
show_trail
=
True
)
sim_scenes/solar_system/sun_earth_jupiter.py
浏览文件 @
3ac5f7a4
...
@@ -8,22 +8,43 @@
...
@@ -8,22 +8,43 @@
# ==============================================================================
# ==============================================================================
from
bodies
import
Sun
,
Earth
,
Jupiter
from
bodies
import
Sun
,
Earth
,
Jupiter
from
common.consts
import
SECONDS_PER_YEAR
,
SECONDS_PER_MONTH
,
AU
from
common.consts
import
SECONDS_PER_YEAR
,
SECONDS_PER_MONTH
,
AU
from
sim_scenes.func
import
mayavi_run
,
ursina_run
from
sim_scenes.func
import
mayavi_run
,
ursina_run
,
camera_look_at
from
simulators.ursina.entities.body_timer
import
TimeData
from
simulators.ursina.ursina_config
import
UrsinaConfig
from
simulators.ursina.ursina_event
import
UrsinaEvent
from
simulators.ursina.ursina_mesh
import
create_line
from
ursina
import
color
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
"""
"""
太阳、地球、木星
太阳、地球、木星
"""
"""
bodies
=
[
bodies
=
[
Sun
(
size_scale
=
5e1
),
# 太阳放大 50 倍
Sun
(
size_scale
=
5e1
),
# 太阳放大 50 倍
Earth
(
size_scale
=
2e3
,
distance_scale
=
1
),
# 地球放大 2000 倍,距离保持不变
Earth
(
size_scale
=
2e3
,
distance_scale
=
1
),
# 地球放大 2000 倍,距离保持不变
Jupiter
(
size_scale
=
5e2
,
distance_scale
=
1
),
# 木星放大 500 倍,距离保持不变
Jupiter
(
size_scale
=
5e2
,
distance_scale
=
1
),
# 木星放大 500 倍,距离保持不变
]
]
sun
,
earth
,
jupiter
=
bodies
[
0
],
bodies
[
1
],
bodies
[
2
]
def
on_ready
():
camera_look_at
(
sun
,
rotation_x
=
None
,
rotation_y
=
None
,
rotation_z
=
None
)
UrsinaConfig
.
trail_length
=
235
UrsinaConfig
.
trail_type
=
"line"
pass
def
on_timer_changed
(
time_data
:
TimeData
):
if
int
(
time_data
.
total_days
)
%
10
==
0
:
# print(time_data.total_hours)
create_line
(
from_pos
=
jupiter
.
planet
.
position
,
to_pos
=
earth
.
planet
.
position
,
color
=
color
.
white
)
# 使用 mayavi 查看的运行效果
UrsinaEvent
.
on_ready_subscription
(
on_ready
)
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45
)
UrsinaEvent
.
on_timer_changed_subscription
(
on_timer_changed
)
# 使用 ursina 查看的运行效果
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
# position = 左-右+、上+下-、前+后-
ursina_run
(
bodies
,
SECONDS_PER_
MONTH
,
position
=
(
0
,
AU
,
-
4
*
AU
)
,
show_trail
=
True
)
ursina_run
(
bodies
,
SECONDS_PER_
YEAR
,
position
=
(
0
,
20
*
AU
,
0
),
show_timer
=
True
,
show_trail
=
True
)
simulators/ursina/entities/body_timer.py
浏览文件 @
3ac5f7a4
...
@@ -50,6 +50,10 @@ class TimeData:
...
@@ -50,6 +50,10 @@ class TimeData:
return
self
.
total_seconds
/
3600
return
self
.
total_seconds
/
3600
@
property
def
total_days
(
self
):
return
self
.
total_hours
/
24
class
BodyTimer
(
Singleton
):
class
BodyTimer
(
Singleton
):
"""
"""
...
...
simulators/ursina/entities/entity_utils.py
浏览文件 @
3ac5f7a4
...
@@ -105,7 +105,9 @@ def create_trails(parent):
...
@@ -105,7 +105,9 @@ def create_trails(parent):
if
last_pos_distance
<
parent
.
trail_scale
*
trail_int_scale
:
# 间隔距离不小于1.2倍的拖尾球体
if
last_pos_distance
<
parent
.
trail_scale
*
trail_int_scale
:
# 间隔距离不小于1.2倍的拖尾球体
return
return
# trail = create_trail_line(parent, pos) # 拖尾为线条
if
UrsinaConfig
.
trail_type
==
"line"
:
trail
=
create_trail_line
(
parent
,
pos
)
# 拖尾为线条
else
:
trail
=
create_trail_sphere
(
parent
,
pos
)
# 拖尾为球体
trail
=
create_trail_sphere
(
parent
,
pos
)
# 拖尾为球体
if
trail
is
not
None
:
if
trail
is
not
None
:
...
...
simulators/ursina/ui/control_ui.py
浏览文件 @
3ac5f7a4
...
@@ -25,6 +25,8 @@ class ControlUI(UiPanel):
...
@@ -25,6 +25,8 @@ class ControlUI(UiPanel):
控制面板界面
控制面板界面
"""
"""
def
component_init
(
self
):
def
component_init
(
self
):
UrsinaEvent
.
after_ready_subscription
(
self
.
after_ready
)
self
.
start_button_text
=
"●"
# 》●▲○◎
self
.
start_button_text
=
"●"
# 》●▲○◎
self
.
pause_button_text
=
"〓"
# 〓 || ‖
self
.
pause_button_text
=
"〓"
# 〓 || ‖
self
.
no_trail_button_text
=
"○ "
self
.
no_trail_button_text
=
"○ "
...
@@ -75,6 +77,9 @@ class ControlUI(UiPanel):
...
@@ -75,6 +77,9 @@ class ControlUI(UiPanel):
return
content
return
content
def
after_ready
(
self
):
self
.
slider_trail_length
.
value
=
UrsinaConfig
.
trail_length
def
after_component_init
(
self
):
def
after_component_init
(
self
):
self
.
sec_per_time_switch
.
x
=
-
0.4
self
.
sec_per_time_switch
.
x
=
-
0.4
self
.
on_off_switch
.
x
=
0.2
self
.
on_off_switch
.
x
=
0.2
...
...
simulators/ursina/ursina_config.py
浏览文件 @
3ac5f7a4
...
@@ -37,6 +37,8 @@ class UrsinaConfig:
...
@@ -37,6 +37,8 @@ class UrsinaConfig:
show_trail
=
False
show_trail
=
False
# 拖尾球体的数量
# 拖尾球体的数量
trail_length
=
100
trail_length
=
100
# 拖尾的类型(球体、线条)
trail_type
=
"sphere"
# trail_type="line" or trail_type="sphere"
# 默认秒数(0表示默认)
# 默认秒数(0表示默认)
seconds_per
=
0
seconds_per
=
0
# # 控制摄像机动作速度(天体越大,速度越快,天体越小,速度越慢)
# # 控制摄像机动作速度(天体越大,速度越快,天体越小,速度越慢)
...
...
simulators/ursina/ursina_event.py
浏览文件 @
3ac5f7a4
...
@@ -26,7 +26,8 @@ class UrsinaEvent:
...
@@ -26,7 +26,8 @@ class UrsinaEvent:
UrsinaEvent
.
on_start_funcs
=
[]
UrsinaEvent
.
on_start_funcs
=
[]
# 运行准备的订阅事件
# 运行准备的订阅事件
UrsinaEvent
.
on_ready_funcs
=
[]
UrsinaEvent
.
on_ready_funcs
=
[]
# 准备后的订阅事件
UrsinaEvent
.
after_ready_funcs
=
[]
# 搜索天体的订阅事件
# 搜索天体的订阅事件
UrsinaEvent
.
on_searching_bodies_funcs
=
[]
UrsinaEvent
.
on_searching_bodies_funcs
=
[]
# 应用运行的订阅事件
# 应用运行的订阅事件
...
@@ -115,6 +116,19 @@ class UrsinaEvent:
...
@@ -115,6 +116,19 @@ class UrsinaEvent:
for
f
in
UrsinaEvent
.
on_ready_funcs
:
for
f
in
UrsinaEvent
.
on_ready_funcs
:
f
()
f
()
@
staticmethod
def
after_ready_subscription
(
fun
):
UrsinaEvent
.
after_ready_funcs
.
append
(
fun
)
@
staticmethod
def
after_ready_unsubscription
(
fun
):
UrsinaEvent
.
after_ready_funcs
.
remove
(
fun
)
@
staticmethod
def
after_ready
():
for
f
in
UrsinaEvent
.
after_ready_funcs
:
f
()
@
staticmethod
@
staticmethod
def
on_start_subscription
(
fun
):
def
on_start_subscription
(
fun
):
UrsinaEvent
.
on_start_funcs
.
append
(
fun
)
UrsinaEvent
.
on_start_funcs
.
append
(
fun
)
...
...
simulators/ursina/ursina_mesh.py
浏览文件 @
3ac5f7a4
...
@@ -98,6 +98,17 @@ def create_label(parent, label, pos, color, scale=50, alpha=1.0):
...
@@ -98,6 +98,17 @@ def create_label(parent, label, pos, color, scale=50, alpha=1.0):
return
text
return
text
def
create_line
(
from_pos
,
to_pos
,
parent
=
None
,
alpha
=
1.0
,
len_scale
=
1
,
set_light_off
=
True
,
color
=
color
.
white
,
thickness
=
1
):
line
=
Entity
(
parent
=
parent
,
model
=
Mesh
(
vertices
=
(
from_pos
*
len_scale
,
to_pos
*
len_scale
),
mode
=
'line'
,
thickness
=
thickness
),
color
=
color
,
alpha
=
alpha
)
if
set_light_off
:
line
.
set_light_off
()
return
line
def
create_arrow_line
(
from_pos
,
to_pos
,
parent
=
None
,
label
=
None
,
def
create_arrow_line
(
from_pos
,
to_pos
,
parent
=
None
,
label
=
None
,
set_light_off
=
True
,
alpha
=
1.0
,
len_scale
=
0.5
,
set_light_off
=
True
,
alpha
=
1.0
,
len_scale
=
0.5
,
color
=
color
.
white
,
thickness
=
2
,
color
=
color
.
white
,
thickness
=
2
,
...
@@ -123,6 +134,7 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None,
...
@@ -123,6 +134,7 @@ def create_arrow_line(from_pos, to_pos, parent=None, label=None,
line
=
Entity
(
parent
=
parent
,
line
=
Entity
(
parent
=
parent
,
model
=
Mesh
(
vertices
=
(
from_pos
*
len_scale
,
to_pos
*
len_scale
),
mode
=
'line'
,
thickness
=
thickness
),
model
=
Mesh
(
vertices
=
(
from_pos
*
len_scale
,
to_pos
*
len_scale
),
mode
=
'line'
,
thickness
=
thickness
),
color
=
color
,
alpha
=
alpha
)
color
=
color
,
alpha
=
alpha
)
arrow
=
Entity
(
parent
=
line
,
model
=
arrow_mesh
,
position
=
to_pos
*
len_scale
,
arrow
=
Entity
(
parent
=
line
,
model
=
arrow_mesh
,
position
=
to_pos
*
len_scale
,
scale
=
thickness
*
arrow_scale
,
color
=
color
,
alpha
=
alpha
)
scale
=
thickness
*
arrow_scale
,
color
=
color
,
alpha
=
alpha
)
arrow
.
look_at
(
to_pos
*
100
)
arrow
.
look_at
(
to_pos
*
100
)
...
...
simulators/ursina_simulator.py
浏览文件 @
3ac5f7a4
...
@@ -281,6 +281,8 @@ class UrsinaSimulator(Simulator):
...
@@ -281,6 +281,8 @@ class UrsinaSimulator(Simulator):
UrsinaEvent
.
on_ready
()
UrsinaEvent
.
on_ready
()
UrsinaEvent
.
after_ready
()
self
.
app
.
run
()
self
.
app
.
run
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录