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

Python超人-宇宙模拟器

上级 96694cd3
...@@ -12,6 +12,7 @@ from bodies.venus import Venus ...@@ -12,6 +12,7 @@ from bodies.venus import Venus
from bodies.moon import Moon from bodies.moon import Moon
from bodies.asteroid import Asteroid from bodies.asteroid import Asteroid
from bodies.asteroids import Asteroids from bodies.asteroids import Asteroids
from bodies.habitable_zone import HabitableZone
# 戴森球 # 戴森球
from bodies.dysen_sphere import DysenSphere from bodies.dysen_sphere import DysenSphere
......
# -*- coding:utf-8 -*-
# title :小行星
# description :小行星
# author :Python超人
# date :2023-07-01
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from bodies.body import Body, AU
class HabitableZone(Body):
"""
模拟太阳系宜居带:
目前认为 太阳系 的宜居带范围是从距离太阳0.95个天文单位 (约1.42亿千米)到 2.4个天文单位(约3.59亿千米)的范围为宜居带,
其宽度约为2.17亿千米, 按照这个标准,太阳系的宜居带中只有三个大型天体,分别是地球、 月球 以及火星(1.52天文单位)。
"""
def __init__(self, name="宜居带", mass=1.9891e30,
init_position=[0, 0, 0],
init_velocity=[0, 0, 0],
texture="green_alpha_1.png", size_scale=1.0,
distance_scale=1.0,
rotation_speed=0.1,
parent=None):
params = {
"name": name,
"mass": mass,
"init_position": init_position,
"init_velocity": init_velocity,
"density": 1.408e3,
"color": (179, 231, 255),
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"parent": parent
}
super().__init__(**params)
# 环状带(inner_radius, outer_radius, subdivisions)
self.torus_zone = 0.95, 2.4, 64
def ignore_gravity_with(self, body):
"""
是否忽略指定天体的引力
@param body:
@return:
"""
# 小行星只对恒星有引力,忽略其他行星的引力
# if body.is_fixed_star:
return True
# return True
if __name__ == '__main__':
asteroids = Asteroids()
print(asteroids)
# -*- coding:utf-8 -*-
# title :太阳系宜居带模拟场景
# description :太阳系宜居带模拟场景(展示的效果为太阳系真实的距离)
# author :Python超人
# date :2023-07-01
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from bodies import Sun, Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, HabitableZone, Asteroids
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_YEAR, AU
from sim_scenes.func import mayavi_run, ursina_run
if __name__ == '__main__':
# 目前认为 太阳系 的宜居带范围是从距离太阳0.95个天文单位 (约1.42亿千米)到 2.4个天文单位(约3.59亿千米)的范围为宜居带,
# 其宽度约为2.17亿千米, 按照这个标准,太阳系的宜居带中只有三个大型天体,分别是地球、 月球 以及火星(1.52天文单位)。
sun = Sun(name="太阳", size_scale=0.5e2) # 太阳放大 80 倍,距离保持不变
bodies = [
sun,
Venus(name="金星", size_scale=1.5e3), # 金星放大 4000 倍,距离保持不变
Earth(name="地球", size_scale=1.5e3), # 地球放大 4000 倍,距离保持不变
Moon(name="月球", size_scale=2e3), # 地球放大 4000 倍,距离保持不变
Mars(name="火星", size_scale=2e3), # 火星放大 4000 倍,距离保持不变
Asteroids(name="小行星群", size_scale=3.2e2,
parent=sun), # 小行星群模拟(仅 ursina 模拟器支持)
HabitableZone(name="宜居带", size_scale=1e2,
parent=sun), # 小行星群模拟(仅 ursina 模拟器支持)
Jupiter(name="木星", size_scale=2e2), # 木星放大 800 倍,距离保持不变
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, 1, position=(0, 2 * AU, -11 * AU),
bg_music="sounds/interstellar.mp3")
...@@ -22,7 +22,7 @@ class CalcView(BodyView): ...@@ -22,7 +22,7 @@ class CalcView(BodyView):
pass pass
def appear(self): def appear(self):
if hasattr(self.body, "torus_stars"): if hasattr(self.body, "torus_stars") or hasattr(self.body, "torus_zone"):
# 暂不支持环状小行星群 # 暂不支持环状小行星群
return return
......
...@@ -94,7 +94,7 @@ class MplSimulator(Simulator): ...@@ -94,7 +94,7 @@ class MplSimulator(Simulator):
update_ax(ax, styles) update_ax(ax, styles)
for idx, body in enumerate(bodies): for idx, body in enumerate(bodies):
if hasattr(body, "torus_stars"): if hasattr(body, "torus_stars") or hasattr(body, "torus_zone"):
# 暂不支持环状小行星群 # 暂不支持环状小行星群
continue continue
......
...@@ -63,6 +63,13 @@ class Planet(Entity): ...@@ -63,6 +63,13 @@ class Planet(Entity):
# 创建一个星环小天体群(主要模拟小行星群,非一个天体) # 创建一个星环小天体群(主要模拟小行星群,非一个天体)
model = create_torus(0.83, 1.05, 64, 1) model = create_torus(0.83, 1.05, 64, 1)
rotation = (90, 0, 0) rotation = (90, 0, 0)
elif hasattr(self.body, "torus_zone"):
# 创建一个星环小天体群(主要模拟环形带,非一个天体)
inner_radius, outer_radius, subdivisions = self.body.torus_zone
if subdivisions is None:
subdivisions = 64
model = create_torus(inner_radius, outer_radius, subdivisions, 1)
rotation = (90, 0, 0)
else: else:
# 创建一个天体 # 创建一个天体
subdivisions = 32 subdivisions = 32
...@@ -126,7 +133,7 @@ class Planet(Entity): ...@@ -126,7 +133,7 @@ class Planet(Entity):
axis_color = color.rgba(*axis_color) axis_color = color.rgba(*axis_color)
self.create_rotate_line(axis_color) self.create_rotate_line(axis_color)
if hasattr(self.body, "torus_stars"): if hasattr(self.body, "torus_stars") or hasattr(self.body, "torus_zone"):
# 星环小天体群(主要模拟小行星群,非一个天体) # 星环小天体群(主要模拟小行星群,非一个天体)
self.set_light_off() self.set_light_off()
self.double_sided = True self.double_sided = True
...@@ -193,7 +200,7 @@ class Planet(Entity): ...@@ -193,7 +200,7 @@ class Planet(Entity):
len_scale=line_scale, color=line_color, thickness=2) len_scale=line_scale, color=line_color, thickness=2)
def change_body_scale(self): def change_body_scale(self):
if hasattr(self.body, "torus_stars"): if hasattr(self.body, "torus_stars") or hasattr(self.body, "torus_zone"):
# 星环小天体群(主要模拟小行星群,非一个天体)不受 body_size_factor 影响 # 星环小天体群(主要模拟小行星群,非一个天体)不受 body_size_factor 影响
self.scale = self.init_scale self.scale = self.init_scale
else: else:
......
...@@ -85,7 +85,7 @@ class MayaviView(BodyView): ...@@ -85,7 +85,7 @@ class MayaviView(BodyView):
天体显示的操作,比如:构建天体视图对象 天体显示的操作,比如:构建天体视图对象
@return: @return:
""" """
if hasattr(self.body, "torus_stars"): if hasattr(self.body, "torus_stars") or hasattr(self.body, "torus_zone"):
# 暂不支持环状小行星群 # 暂不支持环状小行星群
return return
......
...@@ -23,7 +23,7 @@ class MplView(BodyView): ...@@ -23,7 +23,7 @@ class MplView(BodyView):
pass pass
def appear(self): def appear(self):
if hasattr(self.body, "torus_stars"): if hasattr(self.body, "torus_stars") or hasattr(self.body, "torus_zone"):
# 暂不支持环状小行星群 # 暂不支持环状小行星群
return return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册