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

Python超人-宇宙模拟器

上级 55c3f312
......@@ -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, ignore_mass=False, trail_color=None):
rotation_speed=15, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Earth(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -76,7 +76,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.45, ignore_mass=False):
rotation_speed=0.45, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -88,7 +88,8 @@ class Alcyone(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -59,7 +59,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.35, ignore_mass=False):
rotation_speed=0.35, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -71,7 +71,8 @@ class Aldebaran(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -60,7 +60,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.25, ignore_mass=False):
rotation_speed=0.25, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -72,7 +72,8 @@ class Antares(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
self.glows = 6
......
......@@ -53,7 +53,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.4, ignore_mass=False):
rotation_speed=0.4, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -65,7 +65,8 @@ class Arcturus(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -55,7 +55,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.5, ignore_mass=False):
rotation_speed=0.5, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -67,7 +67,8 @@ class Bellatrix(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -57,7 +57,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.24, ignore_mass=False):
rotation_speed=0.24, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -69,7 +69,8 @@ class Betelgeuse(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -56,7 +56,7 @@ class CarinaeV382(FixedStar):
init_velocity=[0, 0, 0],
color=(255, 172, 40),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.26, ignore_mass=False):
rotation_speed=0.26, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -68,7 +68,8 @@ class CarinaeV382(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -50,7 +50,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.28, ignore_mass=False):
rotation_speed=0.28, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -62,7 +62,8 @@ class EtaCarinae(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -28,7 +28,7 @@ class FixedStar(Body):
color=(0xFF, 0xFF, 0xFF),
texture=None, size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False, density=1.408e3, trail_color=None,
texture_bright=None, texture_contrast=None):
texture_bright=None, texture_contrast=None, show_name=False):
if texture is None or texture == "fixed_star.png":
self.color = color
# bright=1.1, contrast=3.2
......@@ -45,7 +45,8 @@ class FixedStar(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
super().__init__(**params)
self.light_on = True
......
......@@ -59,7 +59,7 @@ class Pollux(FixedStar):
init_velocity=[0, 0, 0],
color=(0xF5, 0xE8, 0xD5),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.1, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -71,7 +71,8 @@ class Pollux(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -77,7 +77,7 @@ class Procyon(FixedStar):
init_velocity=[0, 0, 0],
color=(0xF5, 0xE8, 0xD5),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.1, ignore_mass=False):
rotation_speed=0.1, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -89,7 +89,8 @@ class Procyon(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -53,7 +53,7 @@ class Rigel(FixedStar):
init_velocity=[0, 0, 0],
color=(200, 200, 255),
texture="fixed_star.png", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.33, ignore_mass=False):
rotation_speed=0.33, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -65,7 +65,8 @@ class Rigel(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
self.glows = 7
......
......@@ -79,7 +79,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.55, ignore_mass=False):
rotation_speed=0.55, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -91,7 +91,8 @@ class Sirius(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -62,7 +62,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.2, ignore_mass=False):
rotation_speed=0.2, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -75,6 +75,7 @@ class Stephenson_2_18(FixedStar):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"show_name": show_name,
"texture_bright": 3,
"texture_contrast": 4
}
......
......@@ -53,7 +53,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.22, ignore_mass=False):
rotation_speed=0.22, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -65,7 +65,8 @@ class UYScuti(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -54,7 +54,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.23, ignore_mass=False):
rotation_speed=0.23, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -67,6 +67,7 @@ class VYCanisMajoris(FixedStar):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"show_name": show_name,
"texture_bright": 2,
"texture_contrast": 3
}
......
......@@ -54,7 +54,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.3, ignore_mass=False):
rotation_speed=0.3, ignore_mass=False, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -66,7 +66,8 @@ class YCanumVenaticorum(FixedStar):
"size_scale": size_scale,
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass
"ignore_mass": ignore_mass,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -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, ignore_mass=False, trail_color=None):
rotation_speed=36.2537, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Jupiter(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=14.6223, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -39,7 +39,8 @@ class Mars(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=0.2558, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Mercury(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=0.5487, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -39,7 +39,8 @@ class Moon(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=22.3463, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Neptune(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=-2.3474, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Pluto(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=33.7711, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Saturn(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -23,7 +23,7 @@ class Sun(FixedStar):
init_velocity=[0, 0, 0],
color=(170, 98, 25),
texture="sun2.jpg", size_scale=1.0, distance_scale=1.0,
rotation_speed=0.6130, ignore_mass=False, trail_color=None):
rotation_speed=0.6130, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -36,7 +36,8 @@ class Sun(FixedStar):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=-20.8816, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Uranus(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
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, ignore_mass=False, trail_color=None):
rotation_speed=-0.0617, ignore_mass=False, trail_color=None, show_name=False):
params = {
"name": name,
"mass": mass,
......@@ -40,7 +40,8 @@ class Venus(Body):
"distance_scale": distance_scale,
"rotation_speed": rotation_speed,
"ignore_mass": ignore_mass,
"trail_color": trail_color
"trail_color": trail_color,
"show_name": show_name
}
super().__init__(**params)
......
......@@ -10,6 +10,7 @@ from PIL import Image
from common.consts import AU
import numpy as np
import random
import os
def get_dominant_colors(infile, resize=(20, 20)):
......@@ -35,7 +36,7 @@ def get_dominant_colors(infile, resize=(20, 20)):
colors = list()
for i in range(min(10,len(color_counts))):
for i in range(min(10, len(color_counts))):
palette_index = color_counts[i][1]
dominant_color = palette[palette_index * 3: palette_index * 3 + 3]
colors.append(tuple(dominant_color))
......@@ -72,6 +73,28 @@ def get_positions_velocitys(angles, velocity=1, radius=1, radius_offset=None, ve
return np.round(pxs, 2), np.round(pys, 2), -np.round(vxs, 2), np.round(vys, 2)
def find_file(file_path, default_val=None, find_deep=5):
"""
代码可能会放到任意级别的目录下面,该函数能逐级往上级目录进行查找文件
@param file_path: 文件路径
@param default_val: 没有找到路径的默认值
@param find_deep: 查找深度
@return:
"""
if file_path is None:
return default_val
if os.path.exists(file_path):
return os.path.normpath(file_path)
for i in range(find_deep):
file_path = os.path.join("..", file_path)
if os.path.exists(file_path):
return os.path.normpath(file_path)
return default_val
def calculate_distance(pos1, pos2=[0, 0, 0]):
"""
计算两点间的距离
......@@ -86,4 +109,5 @@ def calculate_distance(pos1, pos2=[0, 0, 0]):
if __name__ == '__main__':
print(calculate_distance([6, 8, 0], [3, 4, 0]))
# print(calculate_distance([6, 8, 0], [3, 4, 0]))
print(find_file("common/func.py"))
......@@ -55,4 +55,4 @@ if __name__ == '__main__':
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU, -AU / 500),
show_name=True, bg_music="../sounds/universe_03.mp3")
show_name=True, bg_music="sounds/universe_03.mp3")
......@@ -27,4 +27,5 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU / 4, -2 * AU), bg_music="../sounds/universe_02.mp3")
ursina_run(bodies, SECONDS_PER_WEEK, position=(0, AU / 4, -2 * AU),
bg_music="sounds/universe_02.mp3")
......@@ -12,7 +12,7 @@ from sim_scenes.func import ursina_run
if __name__ == '__main__':
"""
高清水星模拟运行
地球晚上模拟运行
"""
bodies = [
Earth(texture="earth_at_night.jpg",
......@@ -22,4 +22,4 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_HOUR / 2, position=(0, 200000, -2000000), cosmic_bg="../textures/cosmic2.jpg")
ursina_run(bodies, SECONDS_PER_HOUR / 2, position=(0, 200000, -2000000), cosmic_bg="textures/cosmic2.jpg")
......@@ -17,9 +17,9 @@ if __name__ == '__main__':
bodies = [
Mercury(texture="mercury_hd.tif",
init_position=[0, 0, 0], init_velocity=[0, 0, 0],
size_scale=100)
size_scale=100, show_name=True)
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 30000, -600000), cosmic_bg="../textures/cosmic1.jpg")
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 30000, -700000), cosmic_bg="textures/cosmic1.jpg")
# -*- coding:utf-8 -*-
# title :高清冥王星模拟运行
# description :高清冥王星模拟运行
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from bodies import Pluto
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY
from sim_scenes.func import ursina_run
if __name__ == '__main__':
"""
高清冥王星模拟运行
"""
bodies = [
Pluto(texture="pluto_hd.jpg",
init_position=[0, 0, 0], init_velocity=[0, 0, 0],
size_scale=100, show_name=True)
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 10000, -450000), cosmic_bg="textures/cosmic1.jpg")
# -*- coding:utf-8 -*-
# title :高清金星模拟运行
# description :高清金星模拟运行
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from bodies import Venus
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY
from sim_scenes.func import ursina_run
if __name__ == '__main__':
"""
高清金星模拟运行
"""
bodies = [
Venus(texture="venus_hd.jpg",
init_position=[0, 0, 0], init_velocity=[0, 0, 0],
size_scale=100, show_name=True)
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_DAY, position=(0, 30000, -1500000), cosmic_bg="textures/cosmic1.jpg")
......@@ -42,4 +42,4 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), bg_music="../sounds/universe_04.mp3")
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU), bg_music="sounds/universe_04.mp3")
......@@ -7,10 +7,9 @@
# python_version :3.8
# ==============================================================================
from bodies import Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Asteroid
from bodies.body import AU
from common.consts import SECONDS_PER_WEEK
from common.func import get_positions_velocitys
from sim_scenes.func import mayavi_run
from common.consts import SECONDS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_MONTH, SECONDS_PER_YEAR, AU
from sim_scenes.func import mayavi_run, ursina_run
import numpy as np
if __name__ == '__main__':
......@@ -46,10 +45,10 @@ if __name__ == '__main__':
# ]
# endregion 1 --------------------------
# region 2.随机构建 60 小行星,注意:太多的小行星会影响电脑性能
NUM_OF_ASTEROIDS = 60
# region 2.随机构建 10 小行星,注意:太多的小行星会影响电脑性能
NUM_OF_ASTEROIDS = 10
asteroids = []
angles = np.linspace(0, 40 * np.pi, NUM_OF_ASTEROIDS)
angles = np.linspace(0, 100 * np.pi, NUM_OF_ASTEROIDS)
pxs, pys, vxs, vys = get_positions_velocitys(angles,
radius=1.60 * AU,
velocity=23.37,
......@@ -82,4 +81,9 @@ if __name__ == '__main__':
# 使用 mayavi 查看的运行效果
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45)
mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45, view_distance=3e9, view_focalpoint=[5e2, 5e2, 5e2])
# mayavi_run(bodies, SECONDS_PER_WEEK, view_azimuth=-45, view_distance=3e9, view_focalpoint=[5e2, 5e2, 5e2])
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 2 * AU, -11 * AU))
\ No newline at end of file
......@@ -20,6 +20,7 @@ from simulators.views.ursina_view import UrsinaView, UrsinaPlayer
from simulators.ursina.ursina_config import UrsinaConfig
from simulators.simulator import Simulator
from common.system import System
from common.func import find_file
import time
import datetime
import math
......@@ -265,7 +266,9 @@ class UrsinaSimulator(Simulator):
# cosmic_bg = '../textures/cosmic1.png'
# cosmic_bg = '../textures/cosmic2.jpg'
cosmic_bg = '../textures/cosmic3.jpg'
import os
cosmic_bg = find_file(cosmic_bg)
if cosmic_bg is not None and os.path.exists(cosmic_bg):
self.cosmic_background(cosmic_bg)
......@@ -289,6 +292,8 @@ class UrsinaSimulator(Simulator):
else:
bg_music = None
bg_music = find_file(bg_music)
if bg_music is None:
# bg_music = "../sounds/universe_04.mp3"
bg_music = "../none"
......
......@@ -18,6 +18,7 @@ from bodies import Body
from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent
from common.color_utils import adjust_brightness, conv_to_vec4_color, get_inverse_color
from common.func import find_file
from simulators.views.body_view import BodyView
from simulators.views.ursina_mesh import create_sphere, create_torus
import numpy as np
......@@ -364,17 +365,21 @@ class Planet(Entity):
创建行星环(使用土星贴图)
:return:
"""
rings_texture = 'textures/saturnRings.jpg'
rings_texture = find_file(rings_texture)
# 行星环偏移角度
# self.ring_rotation_x = 80
# 创建行星环
# self.ring = Entity(parent=self.planet, model='circle', texture='../textures/saturnRings.jpg', scale=3.5,
# self.ring = Entity(parent=self.planet, model='circle', texture=rings_texture, scale=3.5,
# rotation=(self.ring_rotation_x, 0, 0), double_sided=True)
# 行星环偏移角度
self.ring_rotation_x = 80
# 创建行星环
torus = create_torus(0.7, 1.2, 64)
self.ring = Entity(parent=self, model=torus, texture='../textures/saturnRings.jpg', scale=1,
self.ring = Entity(parent=self, model=torus, texture=rings_texture, scale=1,
rotation=(self.ring_rotation_x, 0, 0), double_sided=True)
# 设置行星环不受灯光影响,否则看不清行星环
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册