提交 bb1ef362 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 55381746
......@@ -22,7 +22,7 @@ class CircleObj(Obj):
ignore_mass=False, density=3.51e3, color=(7, 0, 162),
trail_color=None, show_name=False,
parent=None, gravity_only_for=[]):
from ursina.models.procedural.quad import Quad
from ursina.models.procedural.circle import Circle
params = {
"name": name,
"mass": mass,
......
......@@ -45,9 +45,9 @@ if __name__ == '__main__':
]
# endregion
two_way_foil = QuadObj(texture='caustic.jpg', size_scale=2e8,
init_velocity=[-10, -10, 0],
init_position=[0, 0, 39.55 * AU]) \
two_way_foil = QuadObj(texture='caustic.jpg', size_scale=4e7,
init_velocity=[0, 0, 100],
init_position=[0, 0, -10*AU]) \
.set_light_disable(True).set_ignore_gravity(True)
three_dim_bodies = []
......@@ -82,17 +82,90 @@ if __name__ == '__main__':
@return:
"""
# 创建天空
create_sphere_sky(scale=8000)
# camera.clip_plane_near = 0.1
camera.clip_plane_far = 1000000
create_sphere_sky(scale=200000)
for body in two_dim_bodies:
body.planet.enabled = False
model = body.planet.model
if body.three_dim.has_rings:
rings = create_rings(body.planet)
rings.scale *= 2e10
current_stage = None
def stage_01():
"""
二向箔飞向太阳
@return:
"""
global current_stage
if two_bodies_colliding(two_way_foil, sun):
sun.planet.enabled = False
sun.two_dim.planet.enabled = True
# two_way_foil.explode(sun)
two_way_foil.planet.enabled = False
current_stage = stage_02
def blink(body):
if not hasattr(body, "blink_d"):
body.blink_d = 1
body.blink_v = 1
if body.blink_d > 0:
body.blink_v -= 0.05
body.planet.alpha = body.blink_v
if body.blink_v <= 0.7:
body.blink_d = -1
elif body.blink_d < 0:
body.blink_v += 0.05
body.planet.alpha = body.blink_v
if body.blink_v >= 1:
body.blink_d = 1
def stage_02():
"""
@return:
"""
global current_stage
sun.two_dim.planet.init_scale += 1.1
blink(sun.two_dim)
for b in three_dim_bodies:
if two_bodies_colliding(sun.two_dim, b):
b.planet.enabled = False
b.two_dim.planet.enabled = True
if b.two_dim.planet.enabled:
b.two_dim.planet.init_scale += 1.1
blink(b.two_dim)
current_stage = stage_01
def on_timer_changed(time_data):
two_way_foil.planet.rotation_x += 1
two_way_foil.planet.rotation_y += 2
for b in three_dim_bodies:
b.planet.enabled = False
current_stage()
# if sun.two_dim.planet.enabled:
# sun.two_dim.planet.init_scale += 1.1
# for b in three_dim_bodies:
# if two_bodies_colliding(sun.two_dim, b):
# b.planet.enabled = False
# b.two_dim.planet.enabled = True
# if b.two_dim.planet.enabled:
# b.two_dim.planet.init_scale += 1.1
# else:
# if two_bodies_colliding(two_way_foil, sun):
# sun.planet.enabled = False
# sun.two_dim.planet.enabled = True
# for b in three_dim_bodies:
# b.planet.enabled = False
for b in two_dim_bodies:
b.planet.rotation_x = 90
b.init_position = b.three_dim.position
......@@ -110,7 +183,7 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_MONTH, position=(0, 2 * AU, -11 * AU),
ursina_run(bodies, SECONDS_PER_MONTH / 2, position=(0, 2 * AU, -11 * AU),
cosmic_bg='',
timer_enabled=True,
show_grid=False)
......@@ -106,6 +106,10 @@ class Planet(Entity):
# 当对天体大小进行缩放的时候会触发 change_body_scale
UrsinaEvent.on_body_size_changed_subscription(self.change_body_scale)
# if model == 'circle':
# from ursina.models.procedural.circle import Circle
# model = Circle()
super().__init__(
# model="sphere",
model=model,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册