forked from jesstess/ColorWall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheffects.py
More file actions
338 lines (289 loc) · 10.1 KB
/
effects.py
File metadata and controls
338 lines (289 loc) · 10.1 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import random
import time
import ascii8x8
# A dictionary of hsv values for some common colors.
colors = {"black":(0, 0, 0), "white":(0, 0, 1), "gray":(0, 0, 0.5),
"red":(0, 1, 1), "blue":(0.66, 1, 1), "yellow":(0.16, 1, 1),
"purple":(0.85, 1, 0.5), "green":(0.33, 1, 0.5),
"orange":(0.083, 1, 1), "pink":(0.9, 1, 1), "lime":(0.33, 1, 1),
"baby blue":(0.66, 0.5, 1), "cyan":(0.5, 1, 1),
"brown":(0.07, 0.86, 0.54), "beige":(0.083, 0.32, 1),
"indigo":(0.75, 1, 0.5), "dark gray":(0, 0, 0.15),
"light gray":(0, 0, 0.75), "maroon":(0, 1, 0.5),
"navy":(0.66, 1, 0.25)}
def SolidColorTest(wall):
print "SolidColorTest"
wall.clear()
hue = 0
saturation = 1
value = 1
hsv = (hue, saturation, value)
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, hsv)
wall.draw()
time.sleep(2)
def HueTest(wall):
print "HueTest"
wall.clear()
hue = 0
while hue < 1:
hsv = (hue, 1, 1)
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, hsv)
wall.draw()
hue = hue + .01
time.sleep(.05)
def SaturationTest(wall):
print "SaturationTest"
wall.clear()
hue = random.random()
saturation = 0
while saturation < 1:
hsv = (hue, saturation, 1)
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, hsv)
wall.draw()
saturation = saturation + .01
time.sleep(.05)
def ValueTest(wall):
print "ValueTest"
wall.clear()
hue = random.random()
value = 0
while value < 1:
hsv = (hue, 1, value)
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, hsv)
wall.draw()
value = value + .01
time.sleep(.05)
def DictionaryTest(wall):
print "DictionaryTest"
wall.clear()
for color in colors.keys():
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, colors[color])
wall.draw()
time.sleep(0.5)
def RainbowTest(wall):
print "RainbowTest"
wall.clear()
rainbow = [colors["red"], colors["orange"], colors["yellow"],
colors["green"], colors["blue"], colors["purple"]]
for color in rainbow:
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, color)
wall.draw()
time.sleep(.5)
def Checkerboards(wall):
print "Checkerboards"
wall.clear()
for i in range(10):
for x in range(wall.width):
for y in range(wall.height):
if (x + y + i) % 2 == 0:
wall.set_pixel(x, y, colors["black"])
else:
wall.set_pixel(x, y, colors["yellow"])
wall.draw()
time.sleep(0.5)
def Checkerboards2(wall):
print "Checkerboards2"
wall.clear()
for i in range(10):
for x in range(wall.width):
for y in range(wall.height):
if (x + y + i) % 3 == 0:
wall.set_pixel(x, y, colors["black"])
else:
wall.set_pixel(x, y, colors["yellow"])
wall.draw()
time.sleep(0.5)
def Columns(wall):
print "Columns"
wall.clear()
hue = random.random()
start_time = time.time()
while time.time() - start_time < 5:
for x in range(wall.width):
for y in range(wall.height):
hsv = (hue, 1, 1)
wall.set_pixel(x, y, hsv)
wall.draw()
time.sleep(.02)
wall.clear()
hue = (hue + .05) % 1
def Rainbow(wall):
print "Rainbow"
wall.clear()
hue = random.random()
hue_spacing = 1.0/(wall.width * wall.height)
delay = .1
# Draw rainbow stripes from right to left.
for i in range(wall.width - 1, -1, -1):
for j in range(wall.height - 1, -1, -1):
hsv = (hue, 1, 1)
wall.set_pixel(i, j, hsv)
hue += hue_spacing
# on python 2.5, having a hue value of > 1 will return None
# when you try to convert HSV to RGB using colorsys
#
# in later versions, colorsys will treat a hue value of
# > 1 as *just the truncated fractional part*, e.g.
# 1.29 becomes 0.29.
#
# neither of these particularly make sense, but let's
# emulate the behaviour of python 2.6+ here for compatibility's
# sake.
if hue > 1:
hue -= int(hue)
time.sleep(delay)
wall.draw()
time.sleep(1)
# Shift the wall hues for a few seconds.
start_time = time.time()
while time.time() - start_time < 5:
for i in range(wall.width):
for j in range(wall.height):
hsv = wall.get_pixel(i, j)
new_hue = (hsv[0] + hue_spacing/4) % 1
new_hsv = (new_hue, hsv[1], hsv[2])
wall.set_pixel(i, j, new_hsv)
wall.draw()
time.sleep(1)
def Twinkle(wall):
print "Twinkle"
wall.clear()
start_time = time.time()
while time.time() - start_time < 5:
x = random.randint(0, wall.width - 1)
y = random.randint(0, wall.height - 1)
# Stick to blueish colors.
hue = .65 + random.uniform(-1, 1) * .1
value = random.random()
hsv = (hue, 1, value)
wall.set_pixel(x, y, hsv)
wall.draw()
time.sleep(.01)
def KnightMoves(wall):
if wall.width < 2 or wall.height < 2:
return
print "KnightMoves"
wall.clear()
for x in range(wall.width):
for y in range(wall.height):
if (x + y) % 2 == 0:
wall.set_pixel(x, y, colors["black"])
else:
wall.set_pixel(x, y, colors["white"])
# Pick a random starting location for the knight
knight_x = random.randint(0, wall.width - 1)
knight_y = random.randint(0, wall.height - 1)
wall.set_pixel(knight_x, knight_y, colors["red"])
wall.draw()
def move(knight_x, knight_y):
"""
Move the knight.
"""
def getMoves(knight_x, knight_y):
"""
Get all possible moves that the knight can make.
"""
moves = []
# Don't want knight to wrap around the board because you can't
# do that in chess
if (knight_x - 2) >= 0 and (knight_y - 1) >= 0:
moves.append((knight_x - 2, knight_y - 1))
if (knight_x - 1) >= 0 and (knight_y - 2) >= 0:
moves.append((knight_x - 1, knight_y - 2))
if (knight_x - 2) >= 0 and (knight_y + 1) < wall.height:
moves.append((knight_x - 2, knight_y + 1))
if (knight_x + 1) < wall.width and (knight_y - 2) >= 0:
moves.append((knight_x + 1, knight_y - 2))
if (knight_x - 1) >= 0 and (knight_y + 2) < wall.height:
moves.append((knight_x - 1, knight_y + 2))
if (knight_x + 2) < wall.width and (knight_y - 1) >= 0:
moves.append((knight_x + 2, knight_y - 1))
if (knight_x + 2) < wall.width and \
(knight_y + 1) < wall.height:
moves.append((knight_x + 2, knight_y + 1))
if (knight_x + 1) < wall.width and \
(knight_y + 2) < wall.height:
moves.append((knight_x + 1, knight_y + 2))
return moves
start_time = time.time()
while time.time() - start_time < 12:
# Update the knight's position
if (knight_x + knight_y) % 2 == 0:
wall.set_pixel(knight_x, knight_y, colors["black"])
else:
wall.set_pixel(knight_x, knight_y, colors["white"])
moves = getMoves(knight_x, knight_y)
# Select a move at random from the possible moves
knight_x, knight_y = moves[random.randint(0, len(moves) - 1)]
wall.set_pixel(knight_x, knight_y, colors["red"])
wall.draw()
time.sleep(0.75)
def LetterTest(wall):
"""
Cycle through the letters of the alphabet.
Minimum wall size: 8 x 8.
"""
print "LetterTest"
wall.clear()
if wall.width < 8 or wall.height < 8:
return
color = random.random()
foreground = (color, 1, 1)
# Make the foreground and background complementary colors.
background = ((color + .5) % 1, 1, 1)
# Center the letters on the wall
x_offset = int((wall.width - 8) / 2)
y_offset = int((wall.height - 8) / 2)
# Display upper and lower case letters. The break between 90 and 97 is
# for non-letter keyboard characters.
for ord in range(65, 91) + range(97, 123):
wall.clear()
# Set every pixel to the background color, since ascii8x8 will only
# color an 8x8 section.
for x in range(wall.width):
for y in range(wall.height):
wall.set_pixel(x, y, background)
# Color the letter.
ascii8x8.draw_chr(chr(ord), wall, foreground, background,
x_offset, y_offset)
wall.draw()
time.sleep(.1)
def Message(wall):
print "Message"
wall.clear()
message = [
' ',
' ** * * *** * * ** * * * ** ** ** ** * * * ',
' * * * * * * * * * ** * * * * * * * * * * * ',
' ** * * *** * * * ** * * * * * * * * * * ',
' * * * * * * * * * * * * * * * * * ',
' * * * * * ** * * * ** ** ** ** *** * * ',
]
if wall.height < 6 or wall.width < 2:
return
col = 0
start_time = time.time()
while time.time() - start_time < 10:
wall.clear()
for x in range(wall.width):
for y in range(wall.height):
if y >= len(message):
break
dot = message[y][(x+col) % len(message[0])]
if dot != ' ':
wall.set_pixel(x, y, (.333, 1, 1))
wall.draw()
col += 1
time.sleep(0.07)