From 659169d98ad1678ec5288e02370dd92196ac9113 Mon Sep 17 00:00:00 2001 From: march3 Date: Tue, 4 Apr 2023 20:19:03 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?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 --- sim_scenes/earth/__init__.py | 0 sim_scenes/earth/free_fall_of_ball.py | 28 ++++++++++++++++++++++++ sim_scenes/solar_system/earth_moon6.py | 14 +++++------- simulators/ursina/entities/body_trail.py | 11 +++++----- 4 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 sim_scenes/earth/__init__.py create mode 100644 sim_scenes/earth/free_fall_of_ball.py diff --git a/sim_scenes/earth/__init__.py b/sim_scenes/earth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sim_scenes/earth/free_fall_of_ball.py b/sim_scenes/earth/free_fall_of_ball.py new file mode 100644 index 0000000..d59aca3 --- /dev/null +++ b/sim_scenes/earth/free_fall_of_ball.py @@ -0,0 +1,28 @@ +# -*- 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) diff --git a/sim_scenes/solar_system/earth_moon6.py b/sim_scenes/solar_system/earth_moon6.py index ecc64c3..e6ac79d 100644 --- a/sim_scenes/solar_system/earth_moon6.py +++ b/sim_scenes/solar_system/earth_moon6.py @@ -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 查看的运行效果 diff --git a/simulators/ursina/entities/body_trail.py b/simulators/ursina/entities/body_trail.py index 3b0f49d..50bbaf9 100644 --- a/simulators/ursina/entities/body_trail.py +++ b/simulators/ursina/entities/body_trail.py @@ -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() + 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 -- GitLab