()
| 303 | |
| 304 | |
| 305 | def draw_pineao_curve(): |
| 306 | import matplotlib.pyplot as plt |
| 307 | |
| 308 | def peano_curve(level, x, y, dx, dy): |
| 309 | if level == 0: |
| 310 | plt.plot([x, x + dx], [y, y + dy], color="black") |
| 311 | else: |
| 312 | dx /= 3 |
| 313 | dy /= 3 |
| 314 | peano_curve(level - 1, x, y, dx, dy) |
| 315 | peano_curve(level - 1, x + dx, y + dy, dx, dy) |
| 316 | peano_curve(level - 1, x + 2 * dx, y + dy, dx, dy) |
| 317 | peano_curve(level - 1, x + dx, y + 2 * dy, dx, dy) |
| 318 | peano_curve(level - 1, x, y + 2 * dy, dx, dy) |
| 319 | |
| 320 | plt.figure(figsize=(6, 6)) |
| 321 | peano_curve( |
| 322 | 3, 0, 0, 1, 1 |
| 323 | ) # Increase the first argument to increase the complexity of the curve |
| 324 | plt.gca().invert_yaxis() # Invert y axis to match the standard mathematical coordinate system |
| 325 | plt.axis("off") # Hide axes |
| 326 | plt.show() |
| 327 | plt.savefig("peano_curve.png", bbox_inches="tight") |
| 328 | |
| 329 | |
| 330 | if __name__ == "__main__": |
no test coverage detected