From ccb4851049d11125091ccb95ff49725f18db887c Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 24 Mar 2023 16:03:41 +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 --- bodies/body.py | 9 ++++++--- data/gravity_slingshot.json | 22 +++++++++++++++++----- data/sun.json | 2 +- data/sun_earth.json | 20 ++++++++++++++++---- data/tri_bodies_perfect_01.json | 4 +++- data/tri_bodies_perfect_02.json | 4 +++- data/tri_bodies_perfect_03.json | 4 +++- sim_scenes/ursina_json_sim.py | 2 +- 8 files changed, 50 insertions(+), 17 deletions(-) diff --git a/bodies/body.py b/bodies/body.py index abdbad8..3f20dd4 100644 --- a/bodies/body.py +++ b/bodies/body.py @@ -371,12 +371,15 @@ class Body(metaclass=ABCMeta): except Exception as e: err_msg = f"{json_file} 格式错误:" + str(e) raise Exception(err_msg) + is_fixed_star = False if "is_fixed_star" in body_data: if body_data["is_fixed_star"]: - body_data.pop("is_fixed_star") - body = FixedStar(**body_data) - else: + is_fixed_star = True + if is_fixed_star: + body_data.pop("is_fixed_star") body = FixedStar(**body_data) + else: + body = Body(**body_data) bodies.append(body) if "params" in json_data: params = json_data["params"] diff --git a/data/gravity_slingshot.json b/data/gravity_slingshot.json index 7cce92b..b0f9ffa 100644 --- a/data/gravity_slingshot.json +++ b/data/gravity_slingshot.json @@ -24,7 +24,12 @@ "distance_scale": 1.0, "rotation_speed": 0.613, "ignore_mass": false, - "is_fixed_star": true + "is_fixed_star": true, + "trail_color": [ + 170, + 98, + 25 + ] }, { "name": "地球", @@ -50,15 +55,22 @@ "distance_scale": 1.0, "rotation_speed": 15, "ignore_mass": false, - "is_fixed_star": false + "is_fixed_star": false, + "trail_color": [ + 1, + 89, + 162 + ] } ], "params": { "dt": 2592000, "position": [ 0, - 149597870.7, - -448793612.09999996 - ] + 74798935.35, + -598391482.8 + ], + "show_trail": true, + "show_name": false } } \ No newline at end of file diff --git a/data/sun.json b/data/sun.json index e1b503f..2c8e66f 100644 --- a/data/sun.json +++ b/data/sun.json @@ -32,7 +32,7 @@ "position": [ 0, 149597870.7, - -448793612.09999996 + -598391482.8 ] } } \ No newline at end of file diff --git a/data/sun_earth.json b/data/sun_earth.json index a1e15ed..c75e113 100644 --- a/data/sun_earth.json +++ b/data/sun_earth.json @@ -24,7 +24,12 @@ "distance_scale": 1.0, "rotation_speed": 0.613, "ignore_mass": false, - "is_fixed_star": true + "is_fixed_star": true, + "trail_color": [ + 170, + 98, + 25 + ] }, { "name": "地球", @@ -50,7 +55,12 @@ "distance_scale": 1, "rotation_speed": 15, "ignore_mass": false, - "is_fixed_star": false + "is_fixed_star": false, + "trail_color": [ + 1, + 89, + 162 + ] } ], "params": { @@ -58,7 +68,9 @@ "position": [ 0, 149597870.7, - -448793612.09999996 - ] + -598391482.8 + ], + "show_trail": true, + "show_name": false } } \ No newline at end of file diff --git a/data/tri_bodies_perfect_01.json b/data/tri_bodies_perfect_01.json index 7750c2b..fe7bdf2 100644 --- a/data/tri_bodies_perfect_01.json +++ b/data/tri_bodies_perfect_01.json @@ -117,6 +117,8 @@ 0, 149597870.7, -1495978707.0 - ] + ], + "show_trail": true, + "show_name": false } } \ No newline at end of file diff --git a/data/tri_bodies_perfect_02.json b/data/tri_bodies_perfect_02.json index 586b9ac..fb83486 100644 --- a/data/tri_bodies_perfect_02.json +++ b/data/tri_bodies_perfect_02.json @@ -94,6 +94,8 @@ 0, 149597870.7, -1495978707.0 - ] + ], + "show_trail": true, + "show_name": false } } \ No newline at end of file diff --git a/data/tri_bodies_perfect_03.json b/data/tri_bodies_perfect_03.json index c99e421..b56337e 100644 --- a/data/tri_bodies_perfect_03.json +++ b/data/tri_bodies_perfect_03.json @@ -94,6 +94,8 @@ 0, 149597870.7, -1495978707.0 - ] + ], + "show_trail": true, + "show_name": false } } \ No newline at end of file diff --git a/sim_scenes/ursina_json_sim.py b/sim_scenes/ursina_json_sim.py index 879099d..d965f08 100644 --- a/sim_scenes/ursina_json_sim.py +++ b/sim_scenes/ursina_json_sim.py @@ -33,7 +33,7 @@ if __name__ == '__main__': dt = params["dt"] if "dt" in params else SECONDS_PER_YEAR position = params["position"] if "position" in params else (0, 0, 0) - show_trail = params["show_trail"] if "show_trail" in params else True + show_trail = params["show_trail"] if "show_trail" in params else False # 使用 ursina 查看的运行效果 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 -- GitLab