-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackground.py
115 lines (75 loc) · 2.2 KB
/
background.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from graphics import *
from time import sleep
from utils import dusk_colors, dawn_colors
from sys import exit
def step_background(w, colors, delay):
'''
Argument(s)
w :: GraphWin
colors :: List of colors
delay :: Delay in seconds between color changes. The delay may be
a floating point number for subsecond precision.
Side effects
Changes the background of w to each of the colors in the provided list in sequence.
The speed of the color sequence is controlled by the delay.
Return value :: None
'''
# TODO: Change this.
time.sleep(delay)
def dusk(w):
'''
Argument(s)
w :: GraphWin
Side effects
Gradually change the background of w from white to black.
Return value :: None
'''
colors = dusk_colors()
# TODO: use step_background()
def dawn(w):
'''
Argument(s)
w :: GraphWin
Side effects
Gradually change the background of w from black to white.
Return value :: None
'''
colors = dawn_colors()
# TODO: use step_background()
def sequence():
return ["red", "blue", "pink", "green", "orange", "white"]
def init():
w = GraphWin("Test window", 500, 500)
w.setBackground("white")
return w
def click_to(w, msg):
print("Click anywhere in the window to %s" % msg)
print(" ==> You clicked on %s" % w.getMouse())
def test_from_dusk_to_dawn(w):
click_to(w, "go from dusk ...")
dusk(w)
dawn(w)
print("... to dawn.")
def test_step_background(w):
colors = sequence()
print("Color sequence %s" % colors)
click_to(w, "step the background slow.")
step_background(w, colors, 1)
click_to(w, "step the background fast.")
step_background(w, colors, 0.2)
def test_set_background(w):
click_to(w, "set the background to yellow.")
w.setBackground("yellow")
click_to(w, "set the background to red.")
w.setBackground("red")
click_to(w, "set the background to white.")
w.setBackground("white")
def main():
w = init()
test_set_background(w)
# test_step_background(w)
# test_from_dusk_to_dawn(w)
click_to(w, "close the window.")
w.close()
if __name__ == "__main__":
main()