Utility function to plot how the given body-system evolves over time. No doctest provided since this function does not have a return value.
(
title: str,
body_system: BodySystem,
x_start: float = -1,
x_end: float = 1,
y_start: float = -1,
y_end: float = 1,
)
| 211 | |
| 212 | |
| 213 | def plot( |
| 214 | title: str, |
| 215 | body_system: BodySystem, |
| 216 | x_start: float = -1, |
| 217 | x_end: float = 1, |
| 218 | y_start: float = -1, |
| 219 | y_end: float = 1, |
| 220 | ) -> None: |
| 221 | """ |
| 222 | Utility function to plot how the given body-system evolves over time. |
| 223 | No doctest provided since this function does not have a return value. |
| 224 | """ |
| 225 | fig = plt.figure() |
| 226 | fig.canvas.manager.set_window_title(title) |
| 227 | ax = plt.axes( |
| 228 | xlim=(x_start, x_end), ylim=(y_start, y_end) |
| 229 | ) # Set section to be plotted |
| 230 | plt.gca().set_aspect("equal") # Fix aspect ratio |
| 231 | |
| 232 | # Each body is drawn as a patch by the plt-function |
| 233 | patches = [ |
| 234 | plt.Circle((body.position_x, body.position_y), body.size, fc=body.color) |
| 235 | for body in body_system.bodies |
| 236 | ] |
| 237 | |
| 238 | for patch in patches: |
| 239 | ax.add_patch(patch) |
| 240 | |
| 241 | # Function called at each step of the animation |
| 242 | def update(frame: int) -> list[plt.Circle]: # noqa: ARG001 |
| 243 | update_step(body_system, DELTA_TIME, patches) |
| 244 | return patches |
| 245 | |
| 246 | anim = animation.FuncAnimation( # noqa: F841 |
| 247 | fig, update, interval=INTERVAL, blit=True |
| 248 | ) |
| 249 | |
| 250 | plt.show() |
| 251 | |
| 252 | |
| 253 | def example_1() -> BodySystem: |
no test coverage detected