Example 3: Random system with many bodies. No doctest provided since this function does not have a return value.
()
| 301 | |
| 302 | |
| 303 | def example_3() -> BodySystem: |
| 304 | """ |
| 305 | Example 3: Random system with many bodies. |
| 306 | No doctest provided since this function does not have a return value. |
| 307 | """ |
| 308 | |
| 309 | bodies = [] |
| 310 | for _ in range(10): |
| 311 | velocity_x = random.uniform(-0.5, 0.5) |
| 312 | velocity_y = random.uniform(-0.5, 0.5) |
| 313 | |
| 314 | # Bodies are created pairwise with opposite velocities so that the |
| 315 | # total impulse remains zero |
| 316 | bodies.append( |
| 317 | Body( |
| 318 | random.uniform(-0.5, 0.5), |
| 319 | random.uniform(-0.5, 0.5), |
| 320 | velocity_x, |
| 321 | velocity_y, |
| 322 | size=0.05, |
| 323 | ) |
| 324 | ) |
| 325 | bodies.append( |
| 326 | Body( |
| 327 | random.uniform(-0.5, 0.5), |
| 328 | random.uniform(-0.5, 0.5), |
| 329 | -velocity_x, |
| 330 | -velocity_y, |
| 331 | size=0.05, |
| 332 | ) |
| 333 | ) |
| 334 | return BodySystem(bodies, 0.01, 10, 0.1) |
| 335 | |
| 336 | |
| 337 | if __name__ == "__main__": |
no test coverage detected