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

太阳系三体模拟器

上级 ab279f2b
......@@ -27,7 +27,7 @@ class Earth(Body):
init_position=[1.12 * AU, 0, 0],
init_velocity=[0, 29.79, 0],
texture="earth1.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=15):
rotation_speed=15, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Earth(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -41,7 +41,7 @@ class Alcyone(FixedStar):
init_velocity=[0, 0, 0],
color=(0xBB, 0xAA, 0xFF),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.45, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -44,7 +44,7 @@ class Aldebaran(FixedStar):
init_velocity=[0, 0, 0],
color=(250, 195, 47),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.35, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -50,7 +50,7 @@ class Antares(FixedStar):
init_velocity=[0, 0, 0],
color=(249,198,83),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.25, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -46,7 +46,7 @@ class Arcturus(FixedStar):
init_velocity=[0, 0, 0],
color=(254,218,185),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.4, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -51,7 +51,7 @@ class Bellatrix(FixedStar):
init_velocity=[0, 0, 0],
color=(122, 187, 255),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.5, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -42,7 +42,7 @@ class Betelgeuse(FixedStar):
init_velocity=[0, 0, 0],
color=(254,162,1),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.24, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -35,7 +35,7 @@ class CarinaeV382(FixedStar):
init_velocity=[0, 0, 0],
color=(255, 244, 89),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.26, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -37,7 +37,7 @@ class EtaCarinae(FixedStar):
init_velocity=[0, 0, 0],
color=(111,140,255),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.28, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -49,7 +49,7 @@ class FixedStar(Body):
}
super().__init__(**params)
self.light_on = True
self.glows = 10
self.glows = (12, 1.005, 0.08)
def gen_texture(self, texture, texture_bright, texture_contrast):
if texture is None:
......
......@@ -41,7 +41,7 @@ class Rigel(FixedStar):
init_velocity=[0, 0, 0],
color=(141,213,227),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.33, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -54,7 +54,7 @@ class Sirius(FixedStar):
init_velocity=[0, 0, 0],
color=(0xFF, 0xFF, 0xFF),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.55, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -50,7 +50,7 @@ class Stephenson_2_18(FixedStar):
init_velocity=[0, 0, 0],
color=(198, 29, 3),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.2, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -36,7 +36,7 @@ class UYScuti(FixedStar):
init_velocity=[0, 0, 0],
color=(255,116,0),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.22, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -50,7 +50,7 @@ class VYCanisMajoris(FixedStar):
init_velocity=[0, 0, 0],
color=(234,90,65),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.23, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -31,7 +31,7 @@ class YCanumVenaticorum(FixedStar):
init_velocity=[0, 0, 0],
color=(255,55,18),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.3, ignore_mass=False):
params = {
"name": name,
"mass": mass,
......
......@@ -27,7 +27,7 @@ class Jupiter(Body):
init_position=[5.2 * AU, 0, 0],
init_velocity=[0, 13.06, 0],
texture="jupiter1.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=36.2537):
rotation_speed=36.2537, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Jupiter(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -26,7 +26,7 @@ class Mars(Body):
init_position=[1.5 * AU, 0, 0],
init_velocity=[0, 24.13, 0],
texture="mars.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=14.6223):
rotation_speed=14.6223, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -37,7 +37,9 @@ class Mars(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Mercury(Body):
init_position=[0.4 * AU, 0, 0],
init_velocity=[0, 47.87, 0],
texture="mercury.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.2558):
rotation_speed=0.2558, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Mercury(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -26,7 +26,7 @@ class Moon(Body):
init_position=[363104 + 1.12 * AU, 0, 0],
init_velocity=[0, 29.79 + 1.023, 0],
texture="moon.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.5487):
rotation_speed=0.5487, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -37,7 +37,9 @@ class Moon(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Neptune(Body):
init_position=[30 * AU, 0, 0],
init_velocity=[0, 5.43, 0],
texture="neptune.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=22.3463):
rotation_speed=22.3463, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Neptune(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Pluto(Body):
init_position=[40 * AU, 0, 0],
init_velocity=[0, 4.7, 0],
texture="pluto.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=-2.3474):
rotation_speed=-2.3474, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Pluto(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Saturn(Body):
init_position=[10 * AU, 0, 0],
init_velocity=[0, 9.64, 0],
texture="saturn.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=33.7711):
rotation_speed=33.7711, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Saturn(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Uranus(Body):
init_position=[19 * AU, 0, 0],
init_velocity=[0, 6.81, 0],
texture="uranus.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=-20.8816):
rotation_speed=-20.8816, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Uranus(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -27,7 +27,7 @@ class Venus(Body):
init_position=[0.72 * AU, 0, 0],
init_velocity=[0, 35, 0],
texture="venus.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=-0.0617):
rotation_speed=-0.0617, ignore_mass=False, trail_color=None):
params = {
"name": name,
"mass": mass,
......@@ -38,7 +38,9 @@ class Venus(Body):
"texture": texture,
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
}
super().__init__(**params)
......
......@@ -18,10 +18,10 @@ if __name__ == '__main__':
"""
# 构建两个天体对象(太阳、地球)
D = 5e5
SIZE_SCALE = 0.02
SIZE_SCALE = 0.5
bodies = [
Earth(size_scale=1, init_velocity=[0, 29.79, 0], distance_scale=0.0006),
Sun(size_scale=SIZE_SCALE), # 太阳
Earth(size_scale=SIZE_SCALE, ignore_mass=True),
Sun(size_scale=SIZE_SCALE, ignore_mass=True), # 太阳
Sirius(size_scale=SIZE_SCALE, ignore_mass=True), # 天狼星A 质量倍数 2.06 半径倍数 1.71
Bellatrix(size_scale=SIZE_SCALE, ignore_mass=True), # 参宿五 质量倍数 8.6 半径倍数 5.75
Alcyone(size_scale=SIZE_SCALE, ignore_mass=True), # 昴宿六 质量倍数 7 半径倍数 10
......@@ -31,9 +31,6 @@ if __name__ == '__main__':
YCanumVenaticorum(size_scale=SIZE_SCALE, ignore_mass=True), # 猎犬座Y 质量倍数 3.0 半径倍数 215
EtaCarinae(size_scale=SIZE_SCALE, ignore_mass=True), # 海山二 质量倍数 100.0 半径倍数 278
CarinaeV382(size_scale=SIZE_SCALE, ignore_mass=True), # 船底座V382 质量倍数 20.0 半径倍数 350
Antares(size_scale=SIZE_SCALE, ignore_mass=True), # 心宿二 质量倍数 12 半径倍数 770
Betelgeuse(size_scale=SIZE_SCALE, ignore_mass=True), # 参宿四 质量倍数 11.6 半径倍数 887
VYCanisMajoris(size_scale=SIZE_SCALE, ignore_mass=True), # 大犬座VY 质量倍数 25 半径倍数 1419.75
......@@ -43,14 +40,18 @@ if __name__ == '__main__':
distance_sum = 0
for idx, body in enumerate(bodies):
body.rotation_speed /= 10
if idx > 1:
if body.is_fixed_star:
body.light_on = False # 关闭灯光效果,只有太阳对地球有灯光效果
d = pow((body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE, 0.75) * 80
# d = (body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE * 1.1 + D
body.init_position = [(distance_sum + d) / 2, (distance_sum + d), 0]
distance_sum += d
if idx == 0:
d = 0
else:
d = pow((body.raduis + bodies[idx - 1].raduis) * SIZE_SCALE, 1.0) * 1.1
# d = (body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE * 1.1 + D
body.init_velocity = [0, 0, 0]
body.init_position = [body.raduis * SIZE_SCALE, (distance_sum + d), AU]
distance_sum += d
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_MONTH, position=(0, 200000, -AU / 200), show_trail=True)
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -AU / 500), show_trail=True)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册