From 21ae8251e7a3825d9f2bd7b811bbce66cc2574c2 Mon Sep 17 00:00:00 2001 From: march3 Date: Tue, 21 Mar 2023 21:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E7=B3=BB=E4=B8=89=E4=BD=93?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bodies/__init__.py | 9 ++++-- bodies/asteroid.py | 2 +- bodies/asteroids.py | 2 +- bodies/body.py | 8 ++++++ bodies/dysen_sphere.py | 2 +- bodies/earth.py | 2 +- bodies/fixed_stars/alcyone.py | 27 ++++++++++++------ bodies/fixed_stars/antares.py | 34 +++++++++++++++++------ bodies/fixed_stars/arcturus.py | 28 ++++++++++++++----- bodies/fixed_stars/betelgeuse.py | 25 ++++++++++++----- bodies/fixed_stars/canis_majoris_vy.py | 3 +- bodies/fixed_stars/carinae_v382.py | 13 +++++---- bodies/fixed_stars/eta_carinae.py | 10 +++++-- bodies/fixed_stars/fixed_star.py | 6 ++++ bodies/fixed_stars/pollux.py | 17 ++++++++++-- bodies/fixed_stars/pollux_b.py | 3 +- bodies/fixed_stars/procyon.py | 20 ++++++++++++-- bodies/fixed_stars/rigel.py | 6 ++-- bodies/fixed_stars/sirius.py | 5 ++-- bodies/fixed_stars/stephenson_2_18.py | 6 ++-- bodies/fixed_stars/wr21a.py | 3 +- bodies/jupiter.py | 2 +- bodies/mars.py | 2 +- bodies/mercury.py | 2 +- bodies/moon.py | 2 +- bodies/neptune.py | 2 +- bodies/pluto.py | 2 +- bodies/saturn.py | 2 +- bodies/sun.py | 6 ++-- bodies/uranus.py | 2 +- bodies/venus.py | 2 +- common/system.py | 7 ++--- scenes/fixed_stars.py | 30 +++++++++++++++----- scenes/func.py | 7 ++--- scenes/sun_earth.py | 7 +++-- simulators/views/ursina_view.py | 38 +++++++++++++++++++------- 36 files changed, 246 insertions(+), 98 deletions(-) diff --git a/bodies/__init__.py b/bodies/__init__.py index 21fe51c..d2aa78e 100644 --- a/bodies/__init__.py +++ b/bodies/__init__.py @@ -1,6 +1,6 @@ +# 太阳系中的天体(不含太阳) from bodies.body import Body from bodies.earth import Earth -from bodies.sun import Sun from bodies.jupiter import Jupiter from bodies.mars import Mars from bodies.mercury import Mercury @@ -16,8 +16,13 @@ from bodies.asteroids import Asteroids # 戴森球 from bodies.dysen_sphere import DysenSphere -# 恒星 +# 恒星(含太阳) from bodies.fixed_stars.fixed_star import FixedStar +from bodies.sun import Sun from bodies.fixed_stars.sirius import Sirius from bodies.fixed_stars.stephenson_2_18 import Stephenson_2_18 from bodies.fixed_stars.rigel import Rigel +from bodies.fixed_stars.alcyone import Alcyone +from bodies.fixed_stars.antares import Antares +from bodies.fixed_stars.arcturus import Arcturus +from bodies.fixed_stars.betelgeuse import Betelgeuse diff --git a/bodies/asteroid.py b/bodies/asteroid.py index 66a4e0d..7779485 100644 --- a/bodies/asteroid.py +++ b/bodies/asteroid.py @@ -26,7 +26,7 @@ class Asteroid(Body):  平均密度: 2.3✕10³ kg/m³ """ - def __init__(self, name="Asteroid", mass=4.1e10, + def __init__(self, name="小行星", mass=4.1e10, init_position=[1.6 * AU, 0, 0], init_velocity=[0, 25.37, 0], texture="", size_scale=1.0, distance_scale=1.0): diff --git a/bodies/asteroids.py b/bodies/asteroids.py index 24e6f07..240feda 100644 --- a/bodies/asteroids.py +++ b/bodies/asteroids.py @@ -26,7 +26,7 @@ class Asteroids(Body):  平均密度: 2.3✕10³ kg/m³ """ - def __init__(self, name="Asteroids", mass=1.9891e30, + def __init__(self, name="小行星群", mass=1.9891e30, init_position=[0, 0, 0], init_velocity=[0, 0, 0], texture="asteroids.png", size_scale=1.0, diff --git a/bodies/body.py b/bodies/body.py index 9cb2848..8b0d9f8 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -257,6 +257,14 @@ class Body(metaclass=ABCMeta): """ return self.__rotation_speed + @rotation_speed.setter + def rotation_speed(self, value): + """ + 自旋速度(度/小时) + :return: + """ + self.__rotation_speed = value + @property def density(self): """ diff --git a/bodies/dysen_sphere.py b/bodies/dysen_sphere.py index 04c6e96..54e93ba 100644 --- a/bodies/dysen_sphere.py +++ b/bodies/dysen_sphere.py @@ -18,7 +18,7 @@ class DysenSphere(Body): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="DysenSphere", mass=2e28, + def __init__(self, name="戴森球", mass=2e28, init_position=[0, 0, 0], init_velocity=[0, 0, 0], color=(170, 98, 25), diff --git a/bodies/earth.py b/bodies/earth.py index c35f560..3122649 100644 --- a/bodies/earth.py +++ b/bodies/earth.py @@ -23,7 +23,7 @@ class Earth(Body):  平均密度: 5507.85 kg/m³ """ - def __init__(self, name="Earth", mass=5.97237e24, + def __init__(self, name="地球", mass=5.97237e24, init_position=[1.12 * AU, 0, 0], init_velocity=[0, 29.79, 0], texture="earth1.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/fixed_stars/alcyone.py b/bodies/fixed_stars/alcyone.py index 345c942..a3c2fac 100644 --- a/bodies/fixed_stars/alcyone.py +++ b/bodies/fixed_stars/alcyone.py @@ -6,19 +6,29 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO class Alcyone(FixedStar): """ - TODO: 昴宿六 (Alcyone) - 质量:5太阳质量 + 昴宿六 (Alcyone) + 质量:7个太阳质量 密度:不详 颜色值:#EFF6FF 直径:6.12倍太阳直径 - 中文名昴宿六外文名Alcyone表面温度13000K;总光度太阳的2,400倍半 径太阳的10倍质 量太阳的7倍视星等2.87自转周期3天光谱型B7III绝对星等-2.76 + 中文名: 昴宿六 + 外文名: Alcyone + 表面温度: 13000K; + 总光度: 太阳的2,400倍 + 半径: 太阳的10倍 + 质量: 太阳的7倍 + 视星等: 2.87 + 自转周期: 3天 + 光谱型: B7III + 绝对星等: -2.76 + ------------------------ == 太阳参数 == 自转周期: 24.47 地球日,自转角速度约为 0.6130 度/小时 = 360/(24.47*24) @@ -26,10 +36,10 @@ class Alcyone(FixedStar): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="昴宿六", mass=5 * MO, + def __init__(self, name="昴宿六", mass=7 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0xEF, 0xF6, 0xFF), + color=(0xBB, 0xAA, 0xFF), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -37,7 +47,7 @@ class Alcyone(FixedStar): "mass": mass, "init_position": init_position, "init_velocity": init_velocity, - "density": 1.408e3, + "density": 9.854, # 10.000676498446115 "color": color, "texture": texture, "size_scale": size_scale, @@ -49,8 +59,9 @@ class Alcyone(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Alcyone() sun = Sun() print(fixed_star) print("质量倍数", fixed_star.mass / sun.mass) - print("半径倍数", fixed_star.raduis / sun.raduis) \ No newline at end of file + print("半径倍数", fixed_star.raduis / sun.raduis) diff --git a/bodies/fixed_stars/antares.py b/bodies/fixed_stars/antares.py index 6e8a689..d03387f 100644 --- a/bodies/fixed_stars/antares.py +++ b/bodies/fixed_stars/antares.py @@ -6,23 +6,37 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO class Antares(FixedStar): """ - TODO: 心宿二,英文名为Antares + 心宿二,英文名为Antares 质 量A:12 ± 0.2 M⊙ B:7.2 M⊙ 半 径A:680–800 R☉;B:5.2 R☉ A:红超巨星 B:蓝矮星 - 质量:为18.6太阳质量 - 大小:为883太阳半径 + 质量:为12太阳质量 + 大小:为680–800太阳半径 颜色:为0xFF, 0x44, 0x00 密度:为0.0037 g/cm³。 - - 中文名心宿二外文名Antares别 名Alpha Scorpii分 类A:红超巨星 B:蓝矮星质 量A:12 ± 0.2 M⊙ B:7.2 M⊙表面温度A:3570 K B:18500 K视星等A:0.6 ~ 1.6 B:5.5绝对星等-5.28 等 [9] 赤 经16时29分24.46秒赤 纬-26°25′55.21″距地距离550 ly(170 pc)U-B 色指数A:M1.5Iab-Ib B:B2.5VB-V 色指数+1.83光 度A:75,900 L☉ (44,700 – 128,900 L☉);B:2754 L☉ [9] 变星类型Lc半 径A:680–800 R☉;B:5.2 R☉ [9] 拼 音xīn xiù èr + 中文名: 心宿二 + 外文名: Antares + 别名: Alpha Scorpii + 分类: A:红超巨星 B:蓝矮星 + 质量: A:12 ± 0.2 M⊙ B:7.2 M⊙ + 表面温度: A:3570 K B:18500 K + 视星等: A:0.6 ~ 1.6 B:5.5 + 绝对星等: -5.28 等 [9] + 赤经: 16时29分24.46秒 + 赤纬: -26°25′55.21″ + 距地距离: 550 ly(170 pc)U-B + 色指数: A:M1.5Iab-Ib B:B2.5VB-V + 色指数: +1.83 + 光度: A:75,900 L☉ (44,700 – 128,900 L☉);B:2754 L☉ [9] + 变星类型: Lc + 半径: A:680–800 R☉;B:5.2 R☉ ------------------------ == 太阳参数 == @@ -31,10 +45,10 @@ class Antares(FixedStar): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="心宿二", mass=18.6 * MO, + def __init__(self, name="心宿二", mass=12 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0xFF, 0x44, 0x00), + color=(249,198,83), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -42,7 +56,7 @@ class Antares(FixedStar): "mass": mass, "init_position": init_position, "init_velocity": init_velocity, - "density": 0.0037e3, + "density": 0.000037, "color": color, "texture": texture, "size_scale": size_scale, @@ -51,9 +65,11 @@ class Antares(FixedStar): "ignore_mass": ignore_mass } super().__init__(**params) + self.glow_num = 6 if __name__ == '__main__': + from bodies import Sun fixed_star = Antares() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/arcturus.py b/bodies/fixed_stars/arcturus.py index f21b00b..27053b7 100644 --- a/bodies/fixed_stars/arcturus.py +++ b/bodies/fixed_stars/arcturus.py @@ -6,20 +6,33 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO class Arcturus(FixedStar): """ - TODO: 大角星 (Arcturus) - 质量:20太阳质量 + 大角星 (Arcturus) + 质量:太阳质量 密度:1.16×10⁻⁴ g/cm³ 颜色值:#FF9100 直径:1,180倍太阳直径 - 中文名大角星外文名Arcturus别 名牧夫座α,牧夫座16 [2] 、α Boötis、天栋分 类恒星(橙巨星)质 量约 1.08 M⊙ [4] 表面温度约 4286 K [4] 视星等-0.05 等 [3] 绝对星等-0.38 等赤 经14时15分39.7秒赤 纬+19°10′56″距地距离36.7 光年半 径25.4±0.2 R☉ [4] 光 度170 L☉ [5] 光谱类型K0III [2] + 中文名大角星 + 外文名Arcturus + 别 名牧夫座α,牧夫座16 [2] 、α Boötis、天栋 + 分 类恒星(橙巨星) + 质 量约 1.08 M⊙ [4] + 表面温度约 4286 K [4] + 视星等-0.05 等 [3] + 绝对星等-0.38 等 + 赤 经14时15分39.7秒 + 赤 纬+19°10′56″ + 距地距离36.7 光年 + 半 径25.4±0.2 R☉ [4] + 光 度170 L☉ [5] + 光谱类型K0III [2] ------------------------ == 太阳参数 == @@ -28,10 +41,10 @@ class Arcturus(FixedStar): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="大角星", mass=20 * MO, + def __init__(self, name="大角星", mass=1.08 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0xFF, 0xF0, 0xE4), + color=(254,218,185), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -39,7 +52,7 @@ class Arcturus(FixedStar): "mass": mass, "init_position": init_position, "init_velocity": init_velocity, - "density": 1.408e3, + "density": 0.0925, "color": color, "texture": texture, "size_scale": size_scale, @@ -51,6 +64,7 @@ class Arcturus(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Arcturus() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/betelgeuse.py b/bodies/fixed_stars/betelgeuse.py index 840bdb7..55ef65f 100644 --- a/bodies/fixed_stars/betelgeuse.py +++ b/bodies/fixed_stars/betelgeuse.py @@ -6,19 +6,29 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO class Betelgeuse(FixedStar): """ TODO: 参宿四 (Betelgeuse) - 质量:20太阳质量 + 质量:11.6太阳质量 密度:1.16×10⁻⁴ g/cm³ 颜色值:#FF9100 - 直径:1,180倍太阳直径 + 直径:887倍太阳直径 - 中文名参宿四外文名Betelgeuse别 名α Orionis分 类红超巨星质 量11.6,11.6 + 5.0 或 11.6 - 3.9 M⊙直 径887 ± 203 或955 ± 217 D⊙表面温度3590 K视星等+0.50(0.0 ~ +1.3)绝对星等-5.85赤 经5时55分10.30秒赤 纬+7°24′25.43″距地距离640 光年光谱型M1-M2Ia-abU-B 色指数+2.06B-V 色指数+1.85光 度90000 ~ 1.5 × 10^5 L⊙变星类型SRc + 中文名参宿四外文名Betelgeuse + 别 名α Orionis + 分 类红超巨星 + 质 量11.6,11.6 + 5.0 或 11.6 - 3.9 M⊙ + 直 径887 ± 203 或955 ± 217 D⊙ + 表面温度3590 K视星等+0.50(0.0 ~ +1.3)绝对星等-5.85 + 赤 经5时55分10.30秒 + 赤 纬+7°24′25.43″ + 距地距离640 光年 + 光谱型M1-M2Ia-abU-B 色指数+2.06B-V 色指数+1.85 + 光 度90000 ~ 1.5 × 10^5 L⊙变星类型SRc ------------------------ == 太阳参数 == @@ -27,10 +37,10 @@ class Betelgeuse(FixedStar): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="参宿四", mass=20 * MO, + def __init__(self, name="参宿四", mass=11.6 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0xFF, 0xF0, 0xE4), + color=(254,162,1), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -38,7 +48,7 @@ class Betelgeuse(FixedStar): "mass": mass, "init_position": init_position, "init_velocity": init_velocity, - "density": 1.408e3, + "density": 0.0000234, "color": color, "texture": texture, "size_scale": size_scale, @@ -50,6 +60,7 @@ class Betelgeuse(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Betelgeuse() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/canis_majoris_vy.py b/bodies/fixed_stars/canis_majoris_vy.py index f9246b1..e930406 100644 --- a/bodies/fixed_stars/canis_majoris_vy.py +++ b/bodies/fixed_stars/canis_majoris_vy.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -66,6 +66,7 @@ class CanisMajorisVY(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = CanisMajorisVY() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/carinae_v382.py b/bodies/fixed_stars/carinae_v382.py index a6d5fda..5ad1c0a 100644 --- a/bodies/fixed_stars/carinae_v382.py +++ b/bodies/fixed_stars/carinae_v382.py @@ -6,21 +6,23 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO class CarinaeV382(FixedStar): """ TODO: 船底座V382(CarinaeV382) - 质量:为14.3太阳质量 质 量20 M⊙ [2] + 质量:为20太阳质量 质 量20 M⊙ [2] 大小:为350太阳半径 半 径700 ± 250 R☉ 颜色:为0xFF, 0xBF, 0x00 密度:为0.008 g/cm³ 中文名船底座V382外文名V382 Carinae别 - 名船底座x、海石增四分 类黄特超巨星质 量20 M⊙ [2] - 表面温度5200 K [2] 视星等3.93 等绝对星等-9 等 [1] 赤 经11时08分35.39秒 [3] 赤 纬-58°58′30.14″ [3] 距地距离约 8900 光年 [1] 半 径700 ± 250 R☉ [4] 光 度316,000 L☉ [1] + 名船底座x、海石增四分 类黄特超巨星 + 质 量20 M⊙ [2] + 表面温度5200 K [2] 视星等3.93 等绝对星等-9 等 [1] 赤 经11时08分35.39秒 [3] 赤 纬-58°58′30.14″ [3] 距地距离约 8900 光年 [1] + 半 径700 ± 250 R☉ [4] 光 度316,000 L☉ [1] ------------------------ == 太阳参数 == 自转周期: 24.47 地球日,自转角速度约为 0.6130 度/小时 = 360/(24.47*24) @@ -28,7 +30,7 @@ class CarinaeV382(FixedStar): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="船底座V382", mass=14.3 * MO, + def __init__(self, name="船底座V382", mass=20 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], color=(0xFF, 0xBF, 0x00), @@ -51,6 +53,7 @@ class CarinaeV382(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = CarinaeV382() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/eta_carinae.py b/bodies/fixed_stars/eta_carinae.py index ab887d3..f13b24c 100644 --- a/bodies/fixed_stars/eta_carinae.py +++ b/bodies/fixed_stars/eta_carinae.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -18,7 +18,12 @@ class EtaCarinae(FixedStar): 颜色:0xFF, 0xD7, 0x00 密度:0.002 g/cm³ - 中文名海山二/船底座 η 星外文名Eta Carinae别 名Eta Car / η Carinae / η Car分 类A:高光度蓝变星 B:主序星发现者爱德蒙·哈雷发现时间1677年质 量100 M⊙(B:50-80M)直 径386809200 km(B:33 393 600Km)表面温度A:9400 ~ 35200 K B:37200 K视星等约 4.3 等(-0.8至7.9)绝对星等-8.6 等赤 经10时45分03.59秒赤 纬-59°41′04.26″距地距离7500 ly(2300 pc)半长轴15.4 AU离心率0.9公转周期2,022.7 ± 1.3 days(5.54 yr)轨道倾角130 ~ 145°光谱型A:LBV B:OU-B 色指数-0.45B-V 色指数+0.61光 度A:5 × 10^6 L☉ B:10^6 L☉ + 中文名海山二/船底座 η 星外文名Eta Carinae别 名Eta Car / η Carinae / η Car + 分 类A:高光度蓝变星 B:主序星发现者爱德蒙·哈雷发现时间1677年 + 质 量100 M⊙(B:50-80M) + 直 径386809200 km(B:33 393 600Km) + 表面温度A:9400 ~ 35200 K B:37200 K视星等约 4.3 等(-0.8至7.9) + 绝对星等-8.6 等赤 经10时45分03.59秒赤 纬-59°41′04.26″距地距离7500 ly(2300 pc)半长轴15.4 AU离心率0.9公转周期2,022.7 ± 1.3 days(5.54 yr)轨道倾角130 ~ 145°光谱型A:LBV B:OU-B 色指数-0.45B-V 色指数+0.61光 度A:5 × 10^6 L☉ B:10^6 L☉ ------------------------ == 太阳参数 == @@ -50,6 +55,7 @@ class EtaCarinae(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = EtaCarinae() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/fixed_star.py b/bodies/fixed_stars/fixed_star.py index 46f9524..04da6f1 100644 --- a/bodies/fixed_stars/fixed_star.py +++ b/bodies/fixed_stars/fixed_star.py @@ -45,13 +45,19 @@ class FixedStar(Body): "ignore_mass": ignore_mass } super().__init__(**params) + self.light_on = True + self.glow_num = 10 def gen_texture(self, texture): + if texture is None: + return None texture_path = find_texture_root_path() if texture_path is None: err_msg = "未找到纹理图片目录" raise Exception(err_msg) save_file = os.path.join(texture_path, "fixed_star_%s.png" % str(self.__class__.__name__).lower()) + if os.path.exists(save_file): + return save_file fixed_star_img = os.path.join(texture_path, texture) gen_fixed_star_texture(self.color, save_file=save_file, fixed_star_img=fixed_star_img) return save_file diff --git a/bodies/fixed_stars/pollux.py b/bodies/fixed_stars/pollux.py index a7eacf1..e8847c9 100644 --- a/bodies/fixed_stars/pollux.py +++ b/bodies/fixed_stars/pollux.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -18,7 +18,19 @@ class Pollux(FixedStar): 颜色值:#F5E8D5 直径:1.84倍太阳直径 - 中文名北河三外文名Pollux别 名双子座β星分 类恒星,橙巨星质 量1.86 M⊙表面温度4770 K视星等1.14 等绝对星等1.08 等自转周期558天赤 经7时45分18.94秒赤 纬+28°01′34.31″距地距离33.78 光年B-V色指数1U-B色指数0.86光 度39L⊙位 置双子座 + 中文名北河三外文名Pollux别 名双子座β星分 类恒星,橙巨星 + 质 量1.86 M⊙ + 表面温度4770 K + 视星等1.14 等 + 绝对星等1.08 等自 + 转周期558天 + 赤 经7时45分18.94秒 + 赤 纬+28°01′34.31″ + 距地距离33.78 光年B-V + 色指数1U-B + 色指数0.86 + 光 度39L⊙ + 位 置双子座 一、北河三比太阳大多少,77.4个太阳 @@ -57,6 +69,7 @@ class Pollux(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Pollux() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/pollux_b.py b/bodies/fixed_stars/pollux_b.py index fbfb858..f7f30be 100644 --- a/bodies/fixed_stars/pollux_b.py +++ b/bodies/fixed_stars/pollux_b.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -57,6 +57,7 @@ class PolluxB(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = PolluxB() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/procyon.py b/bodies/fixed_stars/procyon.py index 0c1ae21..0ad96d8 100644 --- a/bodies/fixed_stars/procyon.py +++ b/bodies/fixed_stars/procyon.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -18,7 +18,22 @@ class Procyon(FixedStar): 颜色值:#F5E8D5 直径:1.84倍太阳直径 - 中文名南河三外文名Procyon别 名小犬座α分 类恒星发现者未知发现时间史前视星等约0.34绝对星等约2.67赤 经7时39分18.1秒赤 纬+5°13′29″距地距离约 11.46 光年半长轴1.18"离心率0.36轨道倾角31.9 度年 龄约1.7×1000000000年星表编号HIP 37279光谱类型F5 IV-V星 座小犬座星 官南河(井宿,朱雀) + 中文名: 南河三 + 外文名: Procyon + 别名: 小犬座α + 分类: 恒星 + 发现者: 未知发现时间史前视星等约0.34绝对星等约2.67 + 赤经: 7时39分18.1秒 + 赤纬: +5°13′29″ + 距地距离: 约 11.46 光年 + 半长轴: 1.18" + 离心率: 0.36 + 轨道倾角: 31.9 度 + 年龄: 约1.7×1000000000年 + 星表编号: IP 37279 + 光谱类型: F5 IV-V + 星座: 小犬座 + 星官: 南河(井宿,朱雀) ------------------------ == 太阳参数 == 自转周期: 24.47 地球日,自转角速度约为 0.6130 度/小时 = 360/(24.47*24) @@ -49,6 +64,7 @@ class Procyon(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Procyon() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/rigel.py b/bodies/fixed_stars/rigel.py index d7be312..3c9820b 100644 --- a/bodies/fixed_stars/rigel.py +++ b/bodies/fixed_stars/rigel.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -39,7 +39,7 @@ class Rigel(FixedStar): def __init__(self, name="参宿七", mass=21 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0x90, 0x90, 0xFF), + color=(141,213,227), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -56,9 +56,11 @@ class Rigel(FixedStar): "ignore_mass": ignore_mass } super().__init__(**params) + self.glow_num = 7 if __name__ == '__main__': + from bodies import Sun fixed_star = Rigel() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/sirius.py b/bodies/fixed_stars/sirius.py index c81ef10..396afbc 100644 --- a/bodies/fixed_stars/sirius.py +++ b/bodies/fixed_stars/sirius.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -52,7 +52,7 @@ class Sirius(FixedStar): def __init__(self, name="天狼星A", mass=2.06 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=(0xFF, 0xF0, 0xE4), + color=(0xFF, 0xFF, 0xFF), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -72,6 +72,7 @@ class Sirius(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = Sirius() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/stephenson_2_18.py b/bodies/fixed_stars/stephenson_2_18.py index e14e1a3..f2556a3 100644 --- a/bodies/fixed_stars/stephenson_2_18.py +++ b/bodies/fixed_stars/stephenson_2_18.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -48,7 +48,7 @@ class Stephenson_2_18(FixedStar): def __init__(self, name="史蒂文森2-18", mass=14.28e5 * MO, init_position=[0, 0, 0], init_velocity=[0, 0, 0], - color=((0xFF, 60, 0)), + color=((198,29,3)), texture="fixed_star.png", size_scale=1.0, distance_scale=1.0, rotation_speed=0.1, ignore_mass=False): params = { @@ -65,9 +65,11 @@ class Stephenson_2_18(FixedStar): "ignore_mass": ignore_mass } super().__init__(**params) + self.glow_num = 5 if __name__ == '__main__': + from bodies import Sun fixed_star = Stephenson_2_18() sun = Sun() print(fixed_star) diff --git a/bodies/fixed_stars/wr21a.py b/bodies/fixed_stars/wr21a.py index a053ba6..fe7ba31 100644 --- a/bodies/fixed_stars/wr21a.py +++ b/bodies/fixed_stars/wr21a.py @@ -6,7 +6,7 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import FixedStar, Sun +from bodies import FixedStar from common.consts import MO @@ -47,6 +47,7 @@ class WR21a(FixedStar): if __name__ == '__main__': + from bodies import Sun fixed_star = WR21a() sun = Sun() print(fixed_star) diff --git a/bodies/jupiter.py b/bodies/jupiter.py index 0d681fc..4d3a9ed 100644 --- a/bodies/jupiter.py +++ b/bodies/jupiter.py @@ -23,7 +23,7 @@ class Jupiter(Body):  平均密度: 1.326 g/cm³ -> -> 1.326✕10³ kg/m³ """ - def __init__(self, name="Jupiter", mass=1.8982e27, + def __init__(self, name="木星", mass=1.8982e27, init_position=[5.2 * AU, 0, 0], init_velocity=[0, 13.06, 0], texture="jupiter1.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/mars.py b/bodies/mars.py index 6ef1a06..49bb1d9 100644 --- a/bodies/mars.py +++ b/bodies/mars.py @@ -22,7 +22,7 @@ class Mars(Body):  天体质量: 6.4171✕10²³  平均密度: 3.9335 g/cm³ -> 3.9335✕10³ kg/m³ """ - def __init__(self, name="Mars", mass=6.4171e23, + def __init__(self, name="火星", mass=6.4171e23, init_position=[1.5 * AU, 0, 0], init_velocity=[0, 24.13, 0], texture="mars.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/mercury.py b/bodies/mercury.py index dff18fe..85fada3 100644 --- a/bodies/mercury.py +++ b/bodies/mercury.py @@ -23,7 +23,7 @@ class Mercury(Body):  平均密度: 5.427 g/cm³ -> 5.427×10³ kg/m³ """ - def __init__(self, name="Mercury", mass=3.3011e23, + def __init__(self, name="水星", mass=3.3011e23, init_position=[0.4 * AU, 0, 0], init_velocity=[0, 47.87, 0], texture="mercury.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/moon.py b/bodies/moon.py index 141eb44..7b18c27 100644 --- a/bodies/moon.py +++ b/bodies/moon.py @@ -22,7 +22,7 @@ class Moon(Body):  平均密度: 3.344 g/cm³ -> 3.344✕10³ kg/m³ """ - def __init__(self, name="Moon", mass=7.342e22, + def __init__(self, name="月球", mass=7.342e22, 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, diff --git a/bodies/neptune.py b/bodies/neptune.py index ecd0599..35051b7 100644 --- a/bodies/neptune.py +++ b/bodies/neptune.py @@ -23,7 +23,7 @@ class Neptune(Body):  平均密度: 1.638 g/cm³ -> 1.638×10³ kg/m³ """ - def __init__(self, name="Neptune", mass=1.0241e26, + def __init__(self, name="海王星", mass=1.0241e26, init_position=[30 * AU, 0, 0], init_velocity=[0, 5.43, 0], texture="neptune.png", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/pluto.py b/bodies/pluto.py index ed4ef37..e96be64 100644 --- a/bodies/pluto.py +++ b/bodies/pluto.py @@ -23,7 +23,7 @@ class Pluto(Body):  平均密度: 1.854 g/cm³(±0.006) -> 1.854×10³ kg/m³ """ - def __init__(self, name="Pluto", mass=1.303e22, + def __init__(self, name="冥王星", mass=1.303e22, init_position=[40 * AU, 0, 0], init_velocity=[0, 4.7, 0], texture="pluto.png", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/saturn.py b/bodies/saturn.py index aecf96a..283113d 100644 --- a/bodies/saturn.py +++ b/bodies/saturn.py @@ -23,7 +23,7 @@ class Saturn(Body):  平均密度: 0.687 g/cm³ -> 0.687×10³ kg/m³ """ - def __init__(self, name="Saturn", mass=5.6834e26, + def __init__(self, name="土星", mass=5.6834e26, init_position=[10 * AU, 0, 0], init_velocity=[0, 9.64, 0], texture="saturn.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/sun.py b/bodies/sun.py index 35554b3..d5e77b8 100644 --- a/bodies/sun.py +++ b/bodies/sun.py @@ -6,10 +6,10 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies.body import Body +from bodies import FixedStar -class Sun(Body): +class Sun(FixedStar): """ 太阳 ------------------------ @@ -18,7 +18,7 @@ class Sun(Body): 平均密度: 1.408×10³ kg/m³ """ - def __init__(self, name="Sun", mass=1.9891e30, + def __init__(self, name="太阳", mass=1.9891e30, init_position=[0, 0, 0], init_velocity=[0, 0, 0], color=(170, 98, 25), diff --git a/bodies/uranus.py b/bodies/uranus.py index 27c9329..c37dc6f 100644 --- a/bodies/uranus.py +++ b/bodies/uranus.py @@ -23,7 +23,7 @@ class Uranus(Body):  平均密度: 1.27 g/cm³ -> 1.27×10³ kg/m³ """ - def __init__(self, name="Uranus", mass=8.681e25, + def __init__(self, name="天王星", mass=8.681e25, init_position=[19 * AU, 0, 0], init_velocity=[0, 6.81, 0], texture="uranus.png", size_scale=1.0, distance_scale=1.0, diff --git a/bodies/venus.py b/bodies/venus.py index f905b0e..60ae198 100644 --- a/bodies/venus.py +++ b/bodies/venus.py @@ -23,7 +23,7 @@ class Venus(Body):  平均密度: 5.24g/cm3 -> 5.24×10³ kg/m³ """ - def __init__(self, name="Venus", mass=4.8675e24, + def __init__(self, name="金星", mass=4.8675e24, init_position=[0.72 * AU, 0, 0], init_velocity=[0, 35, 0], texture="venus.jpg", size_scale=1.0, distance_scale=1.0, diff --git a/common/system.py b/common/system.py index e460b6d..d920719 100644 --- a/common/system.py +++ b/common/system.py @@ -18,16 +18,13 @@ class System(object): 天体系统 """ - def __init__(self, bodies, max_distance=200 * AU, ignore_mass=False): + def __init__(self, bodies, max_distance=200 * AU): """ :param bodies: :param max_distance:系统的最大范围,超出范围的天体就不显示了 """ self.bodies = bodies - if ignore_mass: - for body in self.bodies: - body.ignore_mass = True # self.adjust_distance_and_velocity() self.max_distance = max_distance @@ -184,7 +181,7 @@ class System(object): if calculate_distance(body2.position) > self.max_distance: # 超过了max_distance距离,则消失 body2.appeared = False - if False == body1.appeared or body2.appeared == False: + if not body1.appeared or not body2.appeared: continue if body1 is body2: diff --git a/scenes/fixed_stars.py b/scenes/fixed_stars.py index 830b4be..3b7c386 100644 --- a/scenes/fixed_stars.py +++ b/scenes/fixed_stars.py @@ -6,8 +6,8 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import Sun, Sirius, Rigel, Stephenson_2_18 -from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY +from bodies import Sun, Earth, Sirius, Rigel, Alcyone, Antares, Arcturus, Betelgeuse, Stephenson_2_18 +from common.consts import SECONDS_PER_WEEK, SECONDS_PER_MONTH, SECONDS_PER_YEAR, SECONDS_PER_DAY from scenes.func import mayavi_run, mpl_run, ursina_run from bodies.body import Body, AU @@ -16,14 +16,30 @@ if __name__ == '__main__': 恒星演示 """ # 构建两个天体对象(太阳、地球) + D = 5e5 + SIZE_SCALE = 0.02 bodies = [ - Sun(size_scale=1, init_position=[0, 0, 0]), - Sirius(size_scale=1, init_position=[0, 1 * AU, 0]), - Rigel(size_scale=1, init_position=[0, 2 * AU, 0]), - Stephenson_2_18(size_scale=1, init_position=[0, 3 * AU, 0]) + Earth(size_scale=1, init_velocity=[0, 29.79, 0], distance_scale=0.0006), + Sun(size_scale=SIZE_SCALE), + Sirius(size_scale=SIZE_SCALE, ignore_mass=True), + Alcyone(size_scale=SIZE_SCALE, ignore_mass=True), + Arcturus(size_scale=SIZE_SCALE, ignore_mass=True), + Rigel(size_scale=SIZE_SCALE, ignore_mass=True), + Antares(size_scale=SIZE_SCALE, ignore_mass=True), + # Betelgeuse(size_scale=SIZE_SCALE, ignore_mass=True), + Stephenson_2_18(size_scale=SIZE_SCALE, ignore_mass=True) ] + distance_sum = 0 + for idx, body in enumerate(bodies): + body.rotation_speed /= 50 + if idx > 1: + body.light_on = False # 关闭灯光效果,只有太阳对地球有灯光效果 + d = pow((body.diameter + bodies[idx - 1].diameter) * SIZE_SCALE, 0.75) * 120 + # 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 # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- - ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -5 * AU), ignore_mass=True) + ursina_run(bodies, SECONDS_PER_MONTH, position=(0, 10, -4 * AU / 200)) diff --git a/scenes/func.py b/scenes/func.py index 7326a26..450f951 100644 --- a/scenes/func.py +++ b/scenes/func.py @@ -55,13 +55,12 @@ def mayavi_run(bodies, dt=SECONDS_PER_WEEK, def ursina_run(bodies, dt=SECONDS_PER_HALF_DAY, - position=(4000000, 800000000, 4000000), + position=(0, 0, 0), # view_azimuth=0, light=True, cosmic_bg=None, show_grid=True, - save_as_json=None, - ignore_mass=False): + save_as_json=None): """ :param bodies: 天体 @@ -79,7 +78,7 @@ def ursina_run(bodies, from simulators.ursina_simulator import UrsinaSimulator, UrsinaPlayer from ursina import application, Sequence, camera, held_keys, time, clamp, Entity, Text, color from ursina.prefabs.first_person_controller import FirstPersonController - body_sys = System(bodies, ignore_mass) + body_sys = System(bodies) if save_as_json is not None: try: body_sys.save_to_json(save_as_json, {"dt": dt, "position": position}) diff --git a/scenes/sun_earth.py b/scenes/sun_earth.py index 82a0b66..982bd67 100644 --- a/scenes/sun_earth.py +++ b/scenes/sun_earth.py @@ -6,16 +6,17 @@ # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== -from bodies import Sun, Earth +from bodies import Sun, Earth, Sirius from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, AU from scenes.func import mayavi_run, ursina_run if __name__ == '__main__': """ - 太阳、地球 + 太阳、地球 Sirius(size_scale=0.2, init_position=[0, 0, 0]), """ bodies = [ - Sun(size_scale=5e1), # 太阳放大 50 倍 + Sirius(size_scale=2e1,init_position=[0,0,0]), + Sun(size_scale=5e1,init_position=[0,0,0]), # 太阳放大 50 倍 Earth(size_scale=2e3, distance_scale=1), # 地球放大 2000 倍,距离保持不变 ] diff --git a/simulators/views/ursina_view.py b/simulators/views/ursina_view.py index dde58c1..80610f0 100644 --- a/simulators/views/ursina_view.py +++ b/simulators/views/ursina_view.py @@ -107,13 +107,15 @@ class Planet(Entity): rotation = (0, 0, 0) UrsinaEvent.on_reset_subscription(self.on_reset) - + # color.white + self.plant_color = color.white + # self.plant_color = color.rgba(*self.body_view.color) super().__init__( # model="sphere", model=model, scale=scale, texture=texture, - color=color.white, + color=self.plant_color, position=pos, rotation=rotation # ,double_sided=True ) @@ -295,14 +297,30 @@ class Planet(Entity): # lights = [] # # 创建多个新的 Entity 对象,作为光晕的容器 # _color = color.rgba(1.0, 0.6, 0.2, 1) - _color = self.body_view.body.color - _color = color.rgba(_color[0]/255, _color[1]/255, _color[2]/255, 1) - for i in range(10): - glow_entity = Entity(parent=self, model='sphere', color=_color, - scale=math.pow(1.03, i), alpha=0.1) - for i in range(2): - # 创建 PointLight 对象,作为恒星的灯光源 - light = PointLight(parent=self, intensity=10, range=10, color=color.white) + if hasattr(self.body_view.body, "glow_num"): + glow_num = self.body_view.body.glow_num + if glow_num > 12: + glow_num = 12 + if glow_num > 5: + alpha = 0.1 + elif glow_num > 4: + alpha = 0.2 + elif glow_num > 3: + alpha = 0.3 + elif glow_num > 2: + alpha = 0.4 + + if glow_num > 0: + _color = self.body_view.body.color + _color = color.rgba(_color[0]/255, _color[1]/255, _color[2]/255, 1) + for i in range(glow_num): + glow_entity = Entity(parent=self, model='sphere', color=_color, + scale=math.pow(1.03, i), alpha=alpha) + if hasattr(self.body_view.body, "light_on"): + if self.body_view.body.light_on: + for i in range(2): + # 创建 PointLight 对象,作为恒星的灯光源 + light = PointLight(parent=self, intensity=10, range=10, color=color.white) def create_rings(self): """ -- GitLab