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

Python超人-宇宙模拟器

上级 e33c3ba0
# -*- coding:utf-8 -*-
# title :地月场景模拟
# description :地月场景模拟
# author :Python超人
# date :2023-02-11
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
from bodies import Moon, Earth, Body
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH
from sim_scenes.func import mayavi_run, ursina_run
from bodies.body import AU
if __name__ == '__main__':
"""
地球、6个月球
"""
# 地球在中心位置
e = Earth(init_position=[0, 0, 0], size_scale=1, texture="earth_hd.jpg", init_velocity=[0, 0, 0])
bodies = [
e,
Moon(name='小球', mass=4.4e18, init_position=[0, e.raduis + 500, 0], init_velocity=[0, 0, 0]), # 球在地球上面500km
]
# 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后-
ursina_run(bodies, 60, position=(0, e.raduis + 500, -4500), show_trail=True, view_closely=0.001)
......@@ -15,18 +15,16 @@ if __name__ == '__main__':
"""
地球、6个月球
"""
# 地球的Y方向初始速度
EARTH_INIT_VELOCITY = 0
# 地球在中心位置
e = Earth(init_position=[0, 0, 0], texture="earth_hd.jpg", init_velocity=[0, 0, 0])
bodies = [
e,
Moon(init_position=[e.diameter, 0, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[-e.diameter, 0, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, e.diameter, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, -e.diameter, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, 0, e.diameter], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, 0, -e.diameter], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[e.diameter, 0, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[-e.diameter, 0, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, e.diameter, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, -e.diameter, 0], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, 0, e.diameter], init_velocity=[0, 0, 0]), # 月球在地球
Moon(init_position=[0, 0, -e.diameter], init_velocity=[0, 0, 0]), # 月球在地球
]
# 使用 ursina 查看的运行效果
......
......@@ -38,12 +38,13 @@ class BodyTrail(Entity):
if self.hovered:
if key == 'left mouse down':
# print(key, self)
if hasattr(self, "entity_infos"):
self.show_infos()
def show_infos(self):
if not hasattr(self, "entity_infos"):
return
if not hasattr(self, "origin_alpha"):
self.origin_color = self.color
# self.origin_color = self.color
self.origin_alpha = self.alpha
if len(self.children) > 0:
......@@ -52,7 +53,7 @@ class BodyTrail(Entity):
# self.color = self.origin_color
self.alpha = self.origin_alpha
return
self.alpha = 0.2
self.alpha = 0.3
# self.color = get_inverse_color(self.origin_color)
vel_info, vel_direction, vel_position = self.entity_infos["velocity"]
......@@ -66,7 +67,7 @@ class BodyTrail(Entity):
v_line.enabled = False
a_arrow, a_line, a_text = create_arrow_line((0, 0, 0), tuple(acc_direction), parent=self,
label=acc_info, color=color.yellow, alpha=0.8, arrow_scale=0.5)
label=acc_info, color=color.green, alpha=0.8, arrow_scale=0.5)
if str(acc_info).startswith("0.00"):
a_text.parent = self
a_arrow.enabled = False
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册