Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Python_超人
太阳系三体模拟器
提交
e6620507
太阳系三体模拟器
项目概览
Python_超人
/
太阳系三体模拟器
通知
1075
Star
131
Fork
128
代码
文件
提交
分支
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看板
提交
e6620507
编写于
3月 11, 2023
作者:
三月三net
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/dev'
上级
9cd2a861
be78b7ff
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
8 deletion
+49
-8
README.md
README.md
+1
-1
simulators/ursina_simulator.py
simulators/ursina_simulator.py
+44
-7
simulators/views/ursina_view.py
simulators/views/ursina_view.py
+4
-0
未找到文件。
README.md
浏览文件 @
e6620507
...
...
@@ -9,7 +9,7 @@
我们可以自己通过调整天体的初始坐标、质量和矢量速度等等参数来自定义各种场景来控制天体的运行效果。
# 效果图
<img
src=
"https://gitcode.net/pythoncr/three_body_sim/-/raw/
dev
/images/solar_system_3.png"
width=
"80.7%"
>
<img
src=
"https://gitcode.net/pythoncr/three_body_sim/-/raw/
master
/images/solar_system_3.png"
width=
"80.7%"
>
<img
src=
"https://gitcode.net/pythoncr/three_body_sim/-/raw/master/images/solar_system_1.png"
width=
"40%"
>
<img
src=
"https://gitcode.net/pythoncr/three_body_sim/-/raw/master/images/solar_system_2.png"
width=
"40%"
>
<img
src=
"https://gitcode.net/pythoncr/three_body_sim/-/raw/master/images/three_body_1.png"
width=
"40%"
>
...
...
simulators/ursina_simulator.py
浏览文件 @
e6620507
...
...
@@ -7,7 +7,8 @@
# python_version :3.8
# ==============================================================================
# pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina
from
ursina
import
Ursina
,
window
,
Entity
,
Grid
,
Mesh
,
camera
,
color
,
mouse
,
Vec2
,
Vec3
,
load_texture
,
held_keys
from
ursina
import
Ursina
,
window
,
Entity
,
Grid
,
Mesh
,
camera
,
Text
,
application
,
color
,
mouse
,
Vec2
,
Vec3
,
\
load_texture
,
held_keys
from
ursina.prefabs.first_person_controller
import
FirstPersonController
from
simulators.views.ursina_view
import
UrsinaView
,
UrsinaPlayer
...
...
@@ -24,12 +25,13 @@ class WorldGrid(Entity): # Entity # 定义构造方法
def
__init__
(
self
):
super
().
__init__
()
s
=
100
grid
=
Entity
(
model
=
Grid
(
s
,
s
),
scale
=
s
*
20
,
color
=
color
.
color
(
0
,
0
,
.
1
,
1
),
rotation_x
=
90
,
grid
=
Entity
(
model
=
Grid
(
s
,
s
),
scale
=
s
*
20
,
color
=
color
.
rgba
(
255
,
255
,
255
,
20
),
rotation_x
=
90
,
position
=
(
0
,
-
80
,
0
))
vertsx
=
((
0
,
0
,
0
),
(
10
,
0
,
0
))
Entity
(
model
=
Mesh
(
vertices
=
vertsx
,
mode
=
'line'
,
thickness
=
3
),
color
=
color
.
cyan
).
set_light_off
()
vertsyz
=
[(
0
,
0
,
0
),
(
0
,
10
,
0
),
(
0
,
0
,
0
),
(
0
,
0
,
10
)]
Entity
(
model
=
Mesh
(
vertices
=
vertsyz
,
mode
=
'line'
,
thickness
=
3
),
color
=
color
.
yellow
).
set_light_off
()
# 坐标轴
# vertsx = ((0, 0, 0), (10, 0, 0))
# Entity(model=Mesh(vertices=vertsx, mode='line', thickness=3), color=color.cyan).set_light_off()
# vertsyz = [(0, 0, 0), (0, 10, 0), (0, 0, 0), (0, 0, 10)]
# Entity(model=Mesh(vertices=vertsyz, mode='line', thickness=3), color=color.yellow).set_light_off()
grid
.
set_light_off
()
...
...
@@ -90,7 +92,16 @@ class UrsinaSimulator(Simulator):
if
kwargs
[
"light"
]:
for
v
in
self
.
ursina_views
:
if
v
.
body
.
is_fixed_star
:
v
.
light
=
PointLight
(
parent
=
v
)
# v.light = PointLight(parent=v, intensity=10, range=10, color=color.white)
# v.light.brightness = 10
lights
=
[]
for
i
in
range
(
1
):
# 可以增加多个光源
light
=
PointLight
(
parent
=
v
,
intensity
=
10
,
range
=
10
,
color
=
color
.
white
)
light
.
brightness
=
10
lights
.
append
(
light
)
v
.
lights
=
lights
pass
# PointLight(parent=camera, color=color.white, position=(0, 0, 0))
# AmbientLight(color=color.rgba(100, 100, 100, 0.1))
# DirectionalLight
...
...
@@ -110,6 +121,32 @@ class UrsinaSimulator(Simulator):
self
.
cosmic_background
(
cosmic_bg
)
EditorCamera
()
pause_handler
=
Entity
(
ignore_paused
=
True
)
# 按空格键则暂停
def
pause_handler_input
(
key
):
time_scales
=
[
1
,
10
,
20
,
30
]
if
key
==
'space'
:
application
.
paused
=
not
application
.
paused
# Pause/unpause the game.
elif
key
==
'tab'
:
# application.time_scale 属性控制游戏时间流逝的速度。
# 具体来说,它是一个浮点数,用于调整游戏时间流逝速度的比例,其默认值为 1.0,表示正常速度。
# 当你将它设置为小于 1.0 的值时,游戏时间会变慢,而设置为大于 1.0 的值时,游戏时间则会变快。
for
idx
,
time_scale
in
enumerate
(
time_scales
):
if
int
(
application
.
time_scale
)
==
time_scale
:
if
idx
<
len
(
time_scales
)
-
1
:
application
.
time_scale
=
time_scales
[
idx
+
1
]
break
else
:
application
.
time_scale
=
1
print
(
application
.
time_scale
)
pause_handler
.
input
=
pause_handler_input
# 加载中文字体文件
Text
.
default_font
=
'simsun.ttc'
key_info_str
=
"方位控制[QWEASD + 鼠标] 暂停控制[空格] 摄像机移动速度[Tab]"
key_info
=
Text
(
text
=
key_info_str
,
position
=
(
-
0.8
,
0.5
),
origin
=
(
-
1
,
1
),
background
=
True
)
self
.
app
.
run
()
...
...
simulators/views/ursina_view.py
浏览文件 @
e6620507
...
...
@@ -141,6 +141,10 @@ class UrsinaView(BodyView):
self
.
planet
.
turn
()
if
hasattr
(
self
,
"light"
):
self
.
light
.
position
=
Vec3
(
self
.
planet
.
x
,
self
.
planet
.
y
,
self
.
planet
.
z
)
if
hasattr
(
self
,
"lights"
):
for
light
in
self
.
lights
:
light
.
position
=
Vec3
(
self
.
planet
.
x
,
self
.
planet
.
y
,
self
.
planet
.
z
)
if
hasattr
(
self
,
"ring"
):
self
.
ring
.
position
=
Vec3
(
self
.
planet
.
x
,
self
.
planet
.
y
,
self
.
planet
.
z
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录