-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathnestingPolygons.py
74 lines (57 loc) · 2.07 KB
/
nestingPolygons.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
66
67
68
69
70
71
72
73
74
#CSci 127 Teaching Staff
#January 2021
#A template for a program that draws nested polygons
#Modified by: --- Your Name Here! ---
#Email: --- 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.
DO NOT CHANGE THE CODE IN THIS FUNCTION
"""
t.penup()
t.forward(dist)
t.pendown()
t.color(col)
def nestedPolygon(t, length, sides):
"""
Takes three parameters: a turtle a side length and the number of sides.
The function does the following: if the length is greater than 10,
it repeats sides times: moves forward that length, turns 360/sides degrees.
When that is completed, it calls nestedPolygon(t, length/2, sides).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def fractalPolygon(t, length, sides):
"""
Takes three parameters: a turtle a side length and the number of sides.
The function does the following: if the length is greater than 10,
it repeats sides times: moves forward that length, turns 360/sides degrees,
and calls fractalPolygon(t, length/2, sides).
"""
###################################
### FILL IN YOUR CODE HERE ###
### Other than your name above, ###
### these are the only sections ###
### you change in this program. ###
###################################
def main():
l = int(input('Enter length: '))
s = int(input('Enter number of sides: '))
#check there are enough sides to draw a polygon
if s < 3:
print("A polygon must have at least 3 sides.")
else:
tom = turtle.Turtle()
setUp(tom, -100, "darkgreen")
nestedPolygon(tom, l, s)
tess = turtle.Turtle()
setUp(tess, 100, "steelblue")
fractalPolygon(tess, l, s)
if __name__ == "__main__":
main()