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

Python超人-宇宙模拟器

上级 93a4e893
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
# link :https://gitcode.net/pythoncr/ # link :https://gitcode.net/pythoncr/
# python_version :3.8 # python_version :3.8
# ============================================================================== # ==============================================================================
from ursina import camera
from bodies import Sun, Earth from bodies import Sun, Earth
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, AU from common.consts import SECONDS_PER_DAY, AU
from sim_scenes.func import ursina_run, camera_look_at from sim_scenes.func import ursina_run, camera_look_at
from simulators.ursina.entities.body_timer import TimeData, BodyTimer from simulators.ursina.entities.body_timer import TimeData, BodyTimer
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
from ursina import camera
def create_earth(name, text_color, position): def create_earth(name, text_color, position):
...@@ -101,6 +102,7 @@ if __name__ == '__main__': ...@@ -101,6 +102,7 @@ if __name__ == '__main__':
UrsinaEvent.on_ready_subscription(on_ready) UrsinaEvent.on_ready_subscription(on_ready)
# 运行中,每时每刻都会触发 on_timer_changed # 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(on_timer_changed) UrsinaEvent.on_timer_changed_subscription(on_timer_changed)
# 设置计时器的最小时间单位为天
BodyTimer().min_unit = BodyTimer.MIN_UNIT_DAYS BodyTimer().min_unit = BodyTimer.MIN_UNIT_DAYS
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
......
...@@ -6,14 +6,15 @@ ...@@ -6,14 +6,15 @@
# link :https://gitcode.net/pythoncr/ # link :https://gitcode.net/pythoncr/
# python_version :3.8 # python_version :3.8
# ============================================================================== # ==============================================================================
import math
from bodies import Earth, Moon from bodies import Earth, Moon
from objs import Satellite, Satellite2 from common.consts import SECONDS_PER_HOUR
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH from objs import Satellite
from sim_scenes.func import ursina_run, camera_look_at from sim_scenes.func import ursina_run, camera_look_at
from simulators.ursina.entities.body_timer import TimeData from simulators.ursina.entities.body_timer import TimeData, BodyTimer
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
from simulators.ursina.ursina_mesh import create_connecting_lines from simulators.ursina.ursina_mesh import create_connecting_lines
import math
# 月球绕地球的半径 # 月球绕地球的半径
R = 363104 R = 363104
...@@ -73,7 +74,7 @@ if __name__ == '__main__': ...@@ -73,7 +74,7 @@ if __name__ == '__main__':
if hasattr(earth, "lines"): if hasattr(earth, "lines"):
for line in earth.lines: for line in earth.lines:
destroy(line) destroy(line)
if int(time_data.total_hours) % 3 == 0: if int(time_data.total_hours) % 8 == 0:
# 创建连接线(将卫星列表用线条连接起来) # 创建连接线(将卫星列表用线条连接起来)
earth.lines = create_connecting_lines([ earth.lines = create_connecting_lines([
[satelliteL2, satelliteL3], [satelliteL2, satelliteL3],
...@@ -88,7 +89,8 @@ if __name__ == '__main__': ...@@ -88,7 +89,8 @@ if __name__ == '__main__':
UrsinaEvent.on_ready_subscription(on_ready) UrsinaEvent.on_ready_subscription(on_ready)
# 运行中,每时每刻都会触发 on_timer_changed # 运行中,每时每刻都会触发 on_timer_changed
UrsinaEvent.on_timer_changed_subscription(on_timer_changed) UrsinaEvent.on_timer_changed_subscription(on_timer_changed)
# 设置计时器的最小时间单位为分钟
BodyTimer().min_unit = BodyTimer.MIN_UNIT_MINUTES
bodies = [earth, moon, bodies = [earth, moon,
satelliteL1, satelliteL2, satelliteL3, satelliteL4, satelliteL5] satelliteL1, satelliteL2, satelliteL3, satelliteL4, satelliteL5]
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
......
...@@ -33,16 +33,24 @@ class TimeData: ...@@ -33,16 +33,24 @@ class TimeData:
self.seconds = int(seconds) self.seconds = int(seconds)
self.min_unit = min_unit self.min_unit = min_unit
if days > 1 or years >= 1 or self.min_unit in [BodyTimer.MIN_UNIT_DAYS, BodyTimer.MIN_UNIT_YEARS]: s_days = str(days).rjust(3, " ")
s_days = str(days).rjust(3, " ")
if self.min_unit in [BodyTimer.MIN_UNIT_YEARS]: if self.min_unit in [BodyTimer.MIN_UNIT_YEARS]:
self.time_text = f'{self.years}年' self.time_text = f'{self.years}年'
elif days >= 20 or years >= 1 or self.min_unit in [BodyTimer.MIN_UNIT_DAYS]: elif self.min_unit in [BodyTimer.MIN_UNIT_DAYS]:
self.time_text = f'{self.years}{s_days}天' self.time_text = f'{self.years}{s_days}天'
else: elif self.min_unit in [BodyTimer.MIN_UNIT_MINUTES]:
self.time_text = f'{self.days}{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}' self.time_text = f'{self.days}{self.hours:02d}:{self.minutes:02d}'
elif self.min_unit in [BodyTimer.MIN_UNIT_HOURS]:
self.time_text = f'{self.days}{self.hours:02d}时'
else: else:
self.time_text = f'{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}' if days > 1 or years >= 1:
if days >= 20 or years >= 1:
self.time_text = f'{self.years}{s_days}天'
else:
self.time_text = f'{self.days}{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}'
else:
self.time_text = f'{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}'
@property @property
def total_minutes(self): def total_minutes(self):
...@@ -65,6 +73,8 @@ class BodyTimer(Singleton): ...@@ -65,6 +73,8 @@ class BodyTimer(Singleton):
最后通过公式: 时间 = 距离 / 速度, 从而得到天体运行了多长时间 最后通过公式: 时间 = 距离 / 速度, 从而得到天体运行了多长时间
""" """
MIN_UNIT_SECONDS = "seconds" MIN_UNIT_SECONDS = "seconds"
MIN_UNIT_MINUTES = "minutes"
MIN_UNIT_HOURS = "hours"
MIN_UNIT_DAYS = "days" MIN_UNIT_DAYS = "days"
MIN_UNIT_YEARS = "years" MIN_UNIT_YEARS = "years"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册