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

Python超人-宇宙模拟器

上级 63b6c9c3
......@@ -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.
先完成此消息的编辑!
想要评论请 注册