fixed_stars.py 2.0 KB
Newer Older
三月三net's avatar
三月三net 已提交
1 2 3 4 5 6 7 8
# -*- coding:utf-8 -*-
# title           :恒星演示
# description     :恒星演示
# author          :Python超人
# date            :2023-02-11
# link            :https://gitcode.net/pythoncr/
# python_version  :3.8
# ==============================================================================
三月三net's avatar
三月三net 已提交
9 10
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
三月三net's avatar
三月三net 已提交
11 12 13 14 15 16 17 18
from scenes.func import mayavi_run, mpl_run, ursina_run
from bodies.body import Body, AU

if __name__ == '__main__':
    """
    恒星演示
    """
    # 构建两个天体对象(太阳、地球)
三月三net's avatar
三月三net 已提交
19 20
    D = 5e5
    SIZE_SCALE = 0.02
三月三net's avatar
三月三net 已提交
21
    bodies = [
三月三net's avatar
三月三net 已提交
22 23 24 25 26 27 28 29 30
        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)
三月三net's avatar
三月三net 已提交
31
    ]
三月三net's avatar
三月三net 已提交
32 33 34 35 36 37 38 39 40
    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
三月三net's avatar
三月三net 已提交
41 42 43 44

    # 使用 ursina 查看的运行效果
    # 常用快捷键: P:运行和暂停  O:重新开始  I:显示天体轨迹
    # position = 左-右+、上+下-、前+后-
三月三net's avatar
三月三net 已提交
45
    ursina_run(bodies, SECONDS_PER_MONTH, position=(0, 200000, -AU / 200), show_trail=True)