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

Python超人-宇宙模拟器

上级 a4bdd56e
...@@ -47,6 +47,10 @@ class Asteroid(Body): ...@@ -47,6 +47,10 @@ class Asteroid(Body):
def show_trail(self): def show_trail(self):
return False return False
@show_trail.setter
def show_trail(self, value):
self.__show_trail = value
def ignore_gravity_with(self, body): def ignore_gravity_with(self, body):
""" """
是否忽略指定天体的引力 是否忽略指定天体的引力
......
...@@ -84,10 +84,22 @@ Area.rect.y : {y} ...@@ -84,10 +84,22 @@ Area.rect.y : {y}
print("Pycharm 窗口", rect) print("Pycharm 窗口", rect)
def set_universe_win_pos():
rect = (183, 70, 1536, 863)
r = 1.25
rect = (int(rect[0]/r),int(rect[1]/r),int((rect[2]+rect[0])/r),int((rect[3]+rect[1])/r))
# Area.rect.h: 863
# Area.rect.w: 1536
# Area.rect.x: 183
# Area.rect.y: 70
set_win_pos('宇宙模拟器(universe sim)', rect)
if __name__ == '__main__': if __name__ == '__main__':
# 使用方法: # 使用方法:
# 1、运行 win_pos.py,找到 EV录屏 区域 -> EV录屏 (183, 70, 1536, 863) # 1、运行 win_pos.py,找到 EV录屏 区域 -> EV录屏 (183, 70, 1536, 863)
set_pycharm_win_pos() set_pycharm_win_pos()
# set_universe_win_pos()
# 2、打开 C:\Users\Administrator\AppData\Local\EVCapture\conf\Admin.conf # 2、打开 C:\Users\Administrator\AppData\Local\EVCapture\conf\Admin.conf
# 修改: # 修改:
# Area.rect.h : 863 # Area.rect.h : 863
......
...@@ -663,6 +663,14 @@ def speed_smooth_adjust_test(): ...@@ -663,6 +663,14 @@ def speed_smooth_adjust_test():
plt.show() plt.show()
def create_sphere_sky(texture="bg_pan.jpg", scale=8000):
from common.image_utils import find_texture
from simulators.ursina.entities.sphere_sky import SphereSky
sky_texture = find_texture(texture, None)
if sky_texture is not None:
SphereSky(texture=sky_texture).scale = scale
if __name__ == '__main__': if __name__ == '__main__':
# from bodies import Sun, Earth # from bodies import Sun, Earth
# #
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
# ============================================================================== # ==============================================================================
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroids from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroids
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH, SECONDS_PER_YEAR, AU from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH, SECONDS_PER_YEAR, AU
from sim_scenes.func import mayavi_run, ursina_run from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky
from simulators.ursina.ursina_event import UrsinaEvent
if __name__ == '__main__': if __name__ == '__main__':
# 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿) # 八大行星:木星(♃)、土星(♄)、天王星(♅)、海王星(♆)、地球(⊕)、金星(♀)、火星(♂)、水星(☿)
...@@ -37,8 +38,19 @@ if __name__ == '__main__': ...@@ -37,8 +38,19 @@ if __name__ == '__main__':
Pluto(size_scale=10e3, distance_scale=0.23), # 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除) Pluto(size_scale=10e3, distance_scale=0.23), # 冥王星放大 10000 倍,距离缩小到真实距离的 0.23(从太阳系的行星中排除)
] ]
# endregion # endregion
def on_ready():
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 创建天空
create_sphere_sky(scale=8000)
# 运行前会触发 on_ready
UrsinaEvent.on_ready_subscription(on_ready)
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后- # position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), show_grid=False) ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU),
cosmic_bg='',
show_grid=False)
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
# ============================================================================== # ==============================================================================
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Moon, Asteroids from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Moon, Asteroids
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, AU from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, AU
from sim_scenes.func import mayavi_run, ursina_run from sim_scenes.func import mayavi_run, ursina_run, create_sphere_sky
import math import math
from common.consts import G from common.consts import G
from simulators.ursina.ursina_event import UrsinaEvent
def get_velocity(mass, distance, velocity, target_distance): def get_velocity(mass, distance, velocity, target_distance):
...@@ -86,9 +87,22 @@ if __name__ == '__main__': ...@@ -86,9 +87,22 @@ if __name__ == '__main__':
body.init_velocity = init_velocity body.init_velocity = init_velocity
body_index += 1 body_index += 1
# def on_ready():
# """
# 事件绑定后,模拟器运行前会触发
# @return:
# """
# # 创建天空
# create_sphere_sky(scale=8000)
#
# # 运行前会触发 on_ready
# UrsinaEvent.on_ready_subscription(on_ready)
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后- # position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU),
show_trail=True, # 运行轨迹拖尾效果(通过快捷键 I 控制开关) show_trail=True, # 运行轨迹拖尾效果(通过快捷键 I 控制开关)
show_grid=False,
# cosmic_bg='',
bg_music="sounds/interstellar.mp3") bg_music="sounds/interstellar.mp3")
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# ============================================================================== # ==============================================================================
from bodies import Sun, Earth, Moon from bodies import Sun, Earth, Moon
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH
from sim_scenes.func import mayavi_run, ursina_run, camera_look_at from sim_scenes.func import mayavi_run, ursina_run, camera_look_at, create_sphere_sky
from bodies.body import AU from bodies.body import AU
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
...@@ -32,6 +32,7 @@ if __name__ == '__main__': ...@@ -32,6 +32,7 @@ if __name__ == '__main__':
# moon_pos, moon_vel = [-384400, 0, 0], [EARTH_INIT_VELOCITY, 0, -1.03] # moon_pos, moon_vel = [-384400, 0, 0], [EARTH_INIT_VELOCITY, 0, -1.03]
moon = Moon(init_position=moon_pos, # 距地距离约: 363104 至 405696 km moon = Moon(init_position=moon_pos, # 距地距离约: 363104 至 405696 km
init_velocity=moon_vel, init_velocity=moon_vel,
rotation_speed=0.40,
size_scale=2e1) # 月球放大 20 倍,距离保持不变 size_scale=2e1) # 月球放大 20 倍,距离保持不变
bodies = [ bodies = [
sun, sun,
...@@ -42,6 +43,18 @@ if __name__ == '__main__': ...@@ -42,6 +43,18 @@ if __name__ == '__main__':
] ]
def on_ready():
"""
事件绑定后,模拟器运行前会触发
@return:
"""
# 运行前触发
# 创建天空
create_sphere_sky(scale=8000)
moon.planet.rotation_y = 90
def on_timer_changed(time_data): def on_timer_changed(time_data):
camera_look_at(moon, rotation_z=0) camera_look_at(moon, rotation_z=0)
...@@ -49,9 +62,15 @@ if __name__ == '__main__': ...@@ -49,9 +62,15 @@ if __name__ == '__main__':
# 订阅事件后,上面的函数功能才会起作用 # 订阅事件后,上面的函数功能才会起作用
# 运行中,每时每刻都会触发 on_timer_changed # 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(on_timer_changed) UrsinaEvent.on_timer_changed_subscription(on_timer_changed)
# 运行前会触发 on_ready
UrsinaEvent.on_ready_subscription(on_ready)
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后- # position = 左-右+、上+下-、前+后-
# position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程 # position=(0, 0, 0) 的位置是站在地球视角,可以观看月相变化的过程
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 0, 0), show_timer=True) ursina_run(bodies, SECONDS_PER_DAY,
position=(0, 0, 0),
show_grid=False,
cosmic_bg='',
show_timer=True)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册