34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
|
|
def save_system_to_file(system, filename="solar_state.txt"):
|
|
with open(filename, "w", encoding="utf-8") as file:
|
|
file.write(f"Saved: {datetime.now()}\n")
|
|
file.write(f"Paused: {system.paused}\n")
|
|
file.write(f"Show orbits: {system.show_orbits}\n")
|
|
file.write(f"Total stars: {len(system.stars)}\n")
|
|
file.write(f"Total planets: {system.get_planet_count()}\n")
|
|
file.write(f"Total objects: {len(system.get_all_objects())}\n")
|
|
file.write(f"Total mass: {system.get_total_mass():.3e}\n\n")
|
|
|
|
for star in system.stars:
|
|
file.write(
|
|
f"{star.name}: "
|
|
f"x={round(star.x, 2)}, y={round(star.y, 2)}, "
|
|
f"radius={star.radius}, mass={star.mass:.3e}\n"
|
|
)
|
|
|
|
for planet in star.planets:
|
|
file.write(
|
|
f" Planet orbit={planet.orbit_number}, "
|
|
f"x={round(planet.x, 2)}, y={round(planet.y, 2)}, "
|
|
f"radius={planet.radius}, "
|
|
f"mass={planet.mass:.3e}, "
|
|
f"angular_speed={round(planet.angular_speed, 4)}, "
|
|
f"linear_speed={round(planet.linear_speed, 4)}, "
|
|
f"direction={planet.direction}, "
|
|
f"angle={round(planet.angle, 4)}, "
|
|
f"orbit_radius={planet.orbit_radius}\n"
|
|
)
|
|
file.write("\n")
|