Recursively draw the Sierpinski triangle given the vertices of the triangle and the recursion depth
(
vertex1: tuple[float, float],
vertex2: tuple[float, float],
vertex3: tuple[float, float],
depth: int,
)
| 46 | |
| 47 | |
| 48 | def triangle( |
| 49 | vertex1: tuple[float, float], |
| 50 | vertex2: tuple[float, float], |
| 51 | vertex3: tuple[float, float], |
| 52 | depth: int, |
| 53 | ) -> None: |
| 54 | """ |
| 55 | Recursively draw the Sierpinski triangle given the vertices of the triangle |
| 56 | and the recursion depth |
| 57 | """ |
| 58 | my_pen.up() |
| 59 | my_pen.goto(vertex1[0], vertex1[1]) |
| 60 | my_pen.down() |
| 61 | my_pen.goto(vertex2[0], vertex2[1]) |
| 62 | my_pen.goto(vertex3[0], vertex3[1]) |
| 63 | my_pen.goto(vertex1[0], vertex1[1]) |
| 64 | |
| 65 | if depth == 0: |
| 66 | return |
| 67 | |
| 68 | triangle(vertex1, get_mid(vertex1, vertex2), get_mid(vertex1, vertex3), depth - 1) |
| 69 | triangle(vertex2, get_mid(vertex1, vertex2), get_mid(vertex2, vertex3), depth - 1) |
| 70 | triangle(vertex3, get_mid(vertex3, vertex2), get_mid(vertex1, vertex3), depth - 1) |
| 71 | |
| 72 | |
| 73 | if __name__ == "__main__": |
no test coverage detected