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

Python超人-宇宙模拟器

上级 2f1943c6
......@@ -13,59 +13,72 @@ from simulators.ursina.entities.body_timer import TimeData
from simulators.ursina.ursina_event import UrsinaEvent
from ursina import camera
def create_earth(name, text_color, position):
"""
创建透明的地球
@param name: 名称
@param text_color: 文字颜色
@param position: 地球的位置
@return:
"""
return Earth(name=name, size_scale=5e3, texture="earth_transparent.png", # 明的地球纹理
text_color=text_color, rotation_speed=0,
init_position=position, init_velocity=[0, 0, 0]).set_ignore_gravity(True) # 忽略重力
if __name__ == '__main__':
"""
太阳、地球
摄像机以太阳的视角看地球(四季和24节气)
"""
sun = Sun(size_scale=5e1, texture="transparent.png") # 太阳使用透明纹理,不会遮挡摄像机
# 在 4 个节气的位置创建固定不动的透明地球
earth_1 = create_earth(name="春分", text_color=(0, 255, 0), position=[-1.05 * AU, 0, 0])
earth_2 = create_earth(name="夏至", text_color=(255, 0, 0), position=[0, 0, -1.05 * AU])
earth_3 = create_earth(name="秋分", text_color=(255, 255, 0), position=[1.05 * AU, 0, 0])
earth_4 = create_earth(name="冬至", text_color=(0, 255, 255), position=[0, 0, 1.05 * AU])
# 运动的地球
earth = Earth(size_scale=5e3, texture="earth_hd.jpg",
text_color=[255, 255, 255], rotation_speed=1,
init_position=[-1 * AU, 0, 0], init_velocity=[0, 0, -29.79])
bodies = [
Sun(size_scale=5e1, texture="transparent.png"), # 太阳透明
Earth(name="中国春天", size_scale=5e3, texture="earth_hd.jpg", text_color=(0, 255, 0),
init_position=[-1 * AU, 0, 0], init_velocity=[0, 0, -29.79]),
Earth(name="中国夏天", size_scale=5e3, texture="earth_hd.jpg", text_color=(255, 0, 0),
init_position=[0, 0, -1 * AU], init_velocity=[29.79, 0, 0]),
Earth(name="中国秋天", size_scale=5e3, texture="earth_hd.jpg", text_color=(255, 255, 0),
init_position=[1 * AU, 0, 0], init_velocity=[0, 0, 29.79]),
Earth(name="中国冬天", size_scale=5e3, texture="earth_hd.jpg", text_color=(0, 255, 255),
init_position=[0, 0, 1 * AU], init_velocity=[-29.79, 0, 0]),
sun, earth,
earth_1, earth_2, earth_3, earth_4,
]
sun = bodies[0]
earth_1 = bodies[1]
earth_2 = bodies[2]
earth_3 = bodies[3]
earth_4 = bodies[4]
# 四季
seasons_angles = [("春天", -135, -45), ("夏天", -180, -135),
("夏天", 135, 180), ("秋天", 45, 135), ("冬天", -45, 45)]
def on_ready():
# 摄像机跟随地球(模拟在地球上看到的效果)
# camera.position = earth.planet.position
# camera.forward = -10 * AU
# # camera.x = camera.x - AU / 100
# camera.look_at(earth.planet)
earth_1.planet.rotation_y += 115 # 春天
earth_2.planet.rotation_y += 15 # 夏天
earth_3.planet.rotation_y -= 80 # 秋天
earth_4.planet.rotation_y -= 145 # 冬天
# 中国农历24节气表
solar_terms_angles = [
("小寒", -22.5, -7.5), ("大寒", -37.5, -22.5), ("立春", -52.5, -37.5), ("雨水", -67.5, -52.5),
("惊蛰", -82.5, -67.5), ("春分", -97.5, -82.5), ("清明", -112.5, -97.5), ("谷雨", -127.5, -112.5),
("立夏", -142.5, -127.5), ("小满", -157.5, -142.5), ("芒种", -172.5, -157.5),
("夏至", -180, -172.5), ("夏至", 172.5, 180),
("小暑", 157.5, 172.5), ("大暑", 142.5, 157.5), ("立秋", 127.5, 142.5), ("处暑", 112.5, 127.5),
("白露", 97.5, 112.5), ("秋分", 82.5, 97.5), ("寒露", 67.5, 82.5), ("霜降", 52.5, 67.5),
("立冬", 37.5, 52.5), ("小雪", 22.5, 37.5), ("大雪", 7.5, 22.5), ("冬至", -7.5, 7.5)]
# camera.parent = sun.planet
camera.look_at(earth_1.planet)
camera.rotation_z = 0
# camera.position=[0,0,0]
pass
# if hasattr(camera, "sky"):
# # 摄像机跟随地球后,需要对深空背景进行调整,否则看到的是黑色背景
# camera.sky.scale = 800
# camera.clip_plane_near = 0.1
# camera.clip_plane_far = 1000000
# # camera.fov = 40
def on_ready():
# 将 4 个节气位置的地球进行旋转,让中国面对太阳
earth_1.planet.rotation_y += 115 # 春分
earth_2.planet.rotation_y += 15 # 夏至
earth_3.planet.rotation_y -= 80 # 秋分
earth_4.planet.rotation_y -= 145 # 冬至
def on_timer_changed(time_data: TimeData):
# 时时刻刻的让地球看向太阳(摄像机跟随地球看向太阳)
# earth.planet.look_at(sun.planet)
# earth.planet.rotation_z = 0
# camera.look_at(earth.planet)
pass
# 摄像机始终看向移动的地球
camera.look_at(earth.planet)
camera.rotation_z = 0
# 根据角度判断,显示中国农历24节气
for info in solar_terms_angles:
if info[1] <= camera.rotation_y < info[2]:
earth.planet.name_text.text = info[0]
# print(camera.rotation_y)
UrsinaEvent.on_ready_subscription(on_ready)
......@@ -74,6 +87,7 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, 1, position=(0, 0, 0),
ursina_run(bodies, SECONDS_PER_DAY * 3,
position=(0, 0, 0), # 摄像机和太阳是相同位置
show_name=True,
show_trail=True)
show_timer=True)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册