-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathnestingSquares.py
65 lines (51 loc) · 1.71 KB
/
nestingSquares.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#CSci 127 Teaching Staff
#September 2020
#A template for a program that draws nested squares
#Modified by: ADD YOUR NAME HERE
#Email: ADD YOUR EMAIL HERE
import turtle
def setUp(t, dist, col):
"""
Takes three parameters, a turtle, t, the distance, dist,
to move the turtle and a color, col, to set the turtle's color.
"""
t.penup()
t.forward(dist)
t.pendown()
t.color(col)
def nested_squares(t, length):
"""
Takes two parameters: a turtle and a length.
The function does the following: if the length is greater than 10,
it repeats 4 times: moves forward that length, turns 90 degrees,
and calls nested_squares(t, length/2).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def fractal_squares(t, length):
"""
Takes two parameters: a turtle and a length.
The function does the following: if the length is greater than 10,
it repeats 4 times: moves forward that length, turns 90 degrees,
and calls fractal_squares(t, length/2).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def main():
n = int(input('Enter length: '))
tom = turtle.Turtle()
setUp(tom, -100, "darkgreen")
nested_squares(tom, n)
tess = turtle.Turtle()
setUp(tess, 100, "steelblue")
fractal_squares(tess, n)
if __name__ == "__main__":
main()