Skip to content

Commit 9f45232

Browse files
authored
Update gosper_curve.py
1 parent 86788d8 commit 9f45232

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

fractals/gosper_curve.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99

1010
def draw_gosper_curve(
11-
side_length: float, depth: int, direction: int = -1, angle: float = 60.0
12-
) -> None:
11+
side_length: float, depth: int, direction: int = -1, angle: float = 60.0) -> None:
1312
"""
1413
Recursively draws a Gosper curve fractal.
1514
@@ -18,8 +17,15 @@ def draw_gosper_curve(
1817
depth: The recursive depth of the curve.
1918
direction: The direction of the drawing (1 or -1).
2019
angle: The angle of the turns in degrees.
21-
"""
2220
21+
Example:
22+
>>> import turtle
23+
>>> # Mocking turtle methods to allow testing without a GUI
24+
>>> turtle.forward = lambda x: None
25+
>>> turtle.left = lambda x: None
26+
>>> turtle.right = lambda x: None
27+
>>> draw_gosper_curve(100.0, 2, -1, 60.0)
28+
"""
2329
if depth == 0:
2430
turtle.forward(side_length)
2531
else:
@@ -56,6 +62,10 @@ def draw_gosper_curve(
5662

5763

5864
if __name__ == "__main__":
65+
import doctest
66+
67+
doctest.testmod()
68+
5969
turtle.title("Gosper Curve")
6070
turtle.penup()
6171
turtle.goto(0, -200)

0 commit comments

Comments
 (0)