diff --git a/objs/textures/two_way_foil_circle.png b/objs/textures/two_way_foil_circle.png index a7f4af7b0785b625a02920323b1d9fc018b2af18..a6045d5cbf03590b5fe9508d3c1ed366b86112c2 100644 Binary files a/objs/textures/two_way_foil_circle.png and b/objs/textures/two_way_foil_circle.png differ diff --git a/sim_scenes/tri_bodies/two_way_foil.py b/sim_scenes/tri_bodies/two_way_foil.py index b072f4b3a9c598d70feea73f159d46b1bd13019c..29c35347392a4fc79083dfe2563e09c2301d332d 100644 --- a/sim_scenes/tri_bodies/two_way_foil.py +++ b/sim_scenes/tri_bodies/two_way_foil.py @@ -17,6 +17,7 @@ from objs import QuadObj, CircleObj, Obj from sim_scenes.func import camera_look_at, two_bodies_colliding from sim_scenes.func import ursina_run, create_sphere_sky from simulators.ursina.ursina_event import UrsinaEvent +from simulators.func import ext_fun_for_method class TwoWayFoilSim: @@ -45,15 +46,6 @@ class TwoWayFoilSim: # endregion init_bodies_pos_vels(self.bodies) - # # 获取模拟的初始位置和速度 - # init_pos_vels = get_init_pos_vels() - # - # for body in self.bodies: - # pos_vels = init_pos_vels.get(type(body).__name__.lower(), None) - # if pos_vels is None: - # continue - # body.init_position = pos_vels['pos'] - # body.init_velocity = pos_vels['vel'] def build_two_way_foil(self): """ @@ -94,6 +86,14 @@ class TwoWayFoilSim: self.two_way_foil_circle.planet.rotation_x = 90 self.two_way_foil_circle.planet.enabled = False + def change_two_way_foil(): + # 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。 + # 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条 + self.two_way_foil.planet.scale_x = 8.5 + self.two_way_foil.planet.scale_y = 5.2 + + ext_fun_for_method(self.two_way_foil.planet, after_run_fun=change_two_way_foil) + def flatten_animation(self, body): """ 天体二维化的动画 diff --git a/sim_scenes/tri_bodies/two_way_foil_02.py b/sim_scenes/tri_bodies/two_way_foil_02.py index 96cd888e3d1a44cfdbfc33951f85bf2fa60b67ed..24b10a59142147117d2d6990762ce217c92a3ae7 100644 --- a/sim_scenes/tri_bodies/two_way_foil_02.py +++ b/sim_scenes/tri_bodies/two_way_foil_02.py @@ -17,6 +17,7 @@ from objs import QuadObj, CircleObj, Obj from sim_scenes.func import camera_look_at, two_bodies_colliding from sim_scenes.func import ursina_run, create_sphere_sky from simulators.ursina.ursina_event import UrsinaEvent +from simulators.func import ext_fun_for_method class TwoWayFoilSim: @@ -94,6 +95,14 @@ class TwoWayFoilSim: self.two_way_foil_circle.planet.rotation_x = 90 self.two_way_foil_circle.planet.enabled = False + def change_two_way_foil(): + # 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。 + # 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条 + self.two_way_foil.planet.scale_x = 8.5 + self.two_way_foil.planet.scale_y = 5.2 + + ext_fun_for_method(self.two_way_foil.planet, after_run_fun=change_two_way_foil) + def flatten_animation(self, body): """ 天体二维化的动画 diff --git a/sim_scenes/tri_bodies/two_way_foil_03.py b/sim_scenes/tri_bodies/two_way_foil_03.py index ac25dba875ab7b04606490ece5c4380275c4a8a2..2cb47a395549e8d4f405e49d4ef4a847419f881c 100644 --- a/sim_scenes/tri_bodies/two_way_foil_03.py +++ b/sim_scenes/tri_bodies/two_way_foil_03.py @@ -18,6 +18,7 @@ from objs import QuadObj, CircleObj, Obj from sim_scenes.func import camera_look_at, two_bodies_colliding from sim_scenes.func import ursina_run, create_sphere_sky from simulators.ursina.ursina_event import UrsinaEvent +from simulators.func import ext_fun_for_method class TwoWayFoilSim: @@ -86,6 +87,14 @@ class TwoWayFoilSim: self.two_way_foil_circle.planet.rotation_x = 90 self.two_way_foil_circle.planet.enabled = False + def change_two_way_foil(): + # 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。 + # 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条 + self.two_way_foil.planet.scale_x = 8.5 + self.two_way_foil.planet.scale_y = 5.2 + + ext_fun_for_method(self.two_way_foil.planet, after_run_fun=change_two_way_foil) + def gen_pixcel_image(self, planet): """ 将纹理图改为像素图片 @@ -165,7 +174,7 @@ class TwoWayFoilSim: self.two_way_foil.planet.enabled = False self.two_way_foil.init_velocity = [0, 0, 0] # 圆形二向箔显示并设置透明度为0.9 - self.two_way_foil_circle.planet.alpha = 0.9 + self.two_way_foil_circle.planet.alpha = 0.8 self.two_way_foil_circle.planet.enabled = True # 当前阶段为 stage_02:二向箔压平天体的阶段 self.current_stage = self.stage_02 diff --git a/sim_scenes/tri_bodies/two_way_foil_04.py b/sim_scenes/tri_bodies/two_way_foil_04.py index 96ed73a20791d67352edd1a063280ffe51becb8a..7b81d387025a78fe683c73383314da1b3e4c6cdb 100644 --- a/sim_scenes/tri_bodies/two_way_foil_04.py +++ b/sim_scenes/tri_bodies/two_way_foil_04.py @@ -17,6 +17,7 @@ from objs import QuadObj, CircleObj, Obj from sim_scenes.func import camera_look_at, two_bodies_colliding from sim_scenes.func import ursina_run, create_sphere_sky from simulators.ursina.ursina_event import UrsinaEvent +from simulators.func import ext_fun_for_method class TwoWayFoilSim: @@ -94,6 +95,14 @@ class TwoWayFoilSim: self.two_way_foil_circle.planet.rotation_x = 90 self.two_way_foil_circle.planet.enabled = False + def change_two_way_foil(): + # 长方形膜状物,长八点五厘米,宽五点二厘米,比一张信用卡略大一些,极薄,看不出任何厚度。 + # 封装状态下晶莹剔透、无色透明。待机模式下由于封装力场逐渐蒸发,会发出白光,使其表面呈纯白色,看上去就是一张纸条 + self.two_way_foil.planet.scale_x = 8.5 + self.two_way_foil.planet.scale_y = 5.2 + + ext_fun_for_method(self.two_way_foil.planet, after_run_fun=change_two_way_foil) + def flatten_animation(self, body): """ 天体二维化的动画 @@ -194,6 +203,7 @@ class TwoWayFoilSim: if self.two_way_foil.planet.enabled: self.two_way_foil.planet.rotation_x += 0.2 self.two_way_foil.planet.rotation_y += 2 + # 摄像机始终看向二向箔 camera_look_at(self.two_way_foil) self.current_stage() diff --git a/simulators/func.py b/simulators/func.py index efbc363a39fd6a1546abab4f10429ecd426fdbba..d510b6fcb5021f2d36fdc62dcd814bf3f4b36eae 100644 --- a/simulators/func.py +++ b/simulators/func.py @@ -138,3 +138,28 @@ def update_ax_styles(ax, styles={}): ax.set_xlabel('X(天文单位:AU)', fontsize="18", color=fore_color) ax.set_ylabel('Y(天文单位:AU)', fontsize="18", color=fore_color) ax.set_zlabel('Z(天文单位:AU)', fontsize="18", color=fore_color) + + +def ext_fun_for_method(obj, method_name='update', before_run_fun=None, after_run_fun=None): + """ + 对方法进行扩展 + @param obj: + @param method_name: + @param before_run_fun: + @param after_run_fun: + @return: + """ + if before_run_fun is None and after_run_fun is None: + return + obj.original_method = getattr(obj, method_name) + + def new_method(): + def warp(): + if callable(before_run_fun): + before_run_fun() + obj.original_method() + if callable(after_run_fun): + after_run_fun() + return warp() + + setattr(obj, method_name, new_method)