-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutant-rainbow.py
61 lines (46 loc) · 1.35 KB
/
mutant-rainbow.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
import random
import turtle as t
def get_line_length():
choice = input('Enter line lenth(long, medium, short): ')
if choice == 'long':
line_length = 250
elif choice == 'medium':
line_length = 200
else:
line_length = 100
return line_length
def get_line_width():
choice = input('Enter line width (superthick, thick, thin): ')
if choice == 'superthick':
line_width = 40
elif choice == 'thick':
line_width = 25
else:
line_width = 10
return line_width
def inside_window():
left_limit = (-t.window_width() / 2) + 100
right_limit = (t.window_width() / 2) - 100
top_limit = (t.window_height() / 2) - 100
bottom_limit = (-t.window_height() / 2) + 100
(x, y) = t.pos()
inside = left_limit < x < right_limit and bottom_limit < y < top_limit
return inside
def move_turtle(line_length):
pen_colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
t.pencolor(random.choice(pen_colors))
if inside_window():
angle = random.randint(0, 180)
t.right(angle)
t.forward(line_length)
else:
t.backward(line_length)
line_length = get_line_length()
line_width = get_line_width()
t.shape('turtle')
t.fillcolor('green')
t.bgcolor('black')
t.speed('fastest')
t.pensize(line_width)
while True:
move_turtle(line_length)