-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfractal_ruler.py
More file actions
45 lines (37 loc) · 1.04 KB
/
fractal_ruler.py
File metadata and controls
45 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Drawing a fractal ruler
Author: Oğuzhan Çölkesen
"""
import turtle
def draw_ruler(height, width, level):
""" Draws a fractal ruler of the desired height, width and level.
Parameters:
height - the height of the ruler (i.e., the height of the vertical ruler
"edge")
width - the width of the ruler (i.e., the length of the middle tick).
level - the recursive level of the ruler.
Returns:
None.
"""
if level == 1:
turtle.right(90)
turtle.forward(height/2)
turtle.left(90)
turtle.forward(width)
turtle.back(width)
turtle.right(90)
turtle.forward(height/2)
else:
draw_ruler(height/2, width/2, level-1)
turtle.left(90)
turtle.forward(width)
turtle.back(width)
draw_ruler(height/2, width/2, level-1)
def main():
""" Tester function. """
turtle.speed('fastest')
draw_ruler(256, 128, 3)
turtle.hideturtle()
turtle.done()
if __name__ == "__main__":
main()