-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblink.py
More file actions
137 lines (109 loc) · 2.98 KB
/
blink.py
File metadata and controls
137 lines (109 loc) · 2.98 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
import time
import sys
import os
from random import randrange
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/..'))
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image, ImageFile
from PIL import PngImagePlugin
ROWS = 32
COLS = 64
ImageFile.LOAD_TRUNCATED_IMAGES = True
options = RGBMatrixOptions()
options.hardware_mapping = 'adafruit-hat'
options.rows = ROWS
options.cols = COLS
options.parallel = 1
matrix = RGBMatrix(options = options)
def show_image(image_file: str):
print(Image.registered_extensions())
image = Image.open(image_file)
print(image.getpixel((1, 1)))
#image.thumbnail((matrix.width, matrix.height), Image.LANCZOS)
image = image.convert("RGB")
print(dir(image))
print(image.getpixel((1,1)))
matrix.SetImage(image)
def fill(r, g, b):
for x in range(COLS):
for y in range(ROWS):
matrix.SetPixel(x, y, r, g, b)
time.sleep(0.005)
def rainbow_fill():
# rd, gd, bd 0 is down 1 is up
r = 255
rd = 1
g = 0
gd = 1
b = 0
bd = 0
#matrix.Clear()
for y in range(ROWS):
for x in range(COLS):
if r == 255 and g == 0 and b == 0: # max red
gd = 1
if g == 255 and r == 255: # Yellow
rd = 0
if g == 255 and r == 0 and b == 0: # max green
bd = 1
if g == 255 and b == 255: # cyan
gd = 0
if b == 255 and r == 0 and g == 0: # max blue
rd = 1
if b == 255 and r == 255: # Purple
bd = 0
if rd:
r += 1
else:
r -= 1
if gd:
g += 1
else:
g -= 1
if bd:
b += 1
else:
b -= 1
if r >= 255:
r = 255
if r <= 0:
r = 0
if g >= 255:
g = 255
if g <= 0:
g = 0
if b >= 255:
b = 255
if b <= 0:
b = 0
matrix.SetPixel(x, y, r, g, b)
time.sleep(0.005)
time.sleep(5)
def rand_fill():
#matrix.Clear()
for _ in range(1000):
r = randrange(256)
g = randrange(256)
b = randrange(256)
x = randrange(64)
y = randrange(32)
matrix.SetPixel(x, y, r, g, b)
time.sleep(0.01)
def drop_fill():
for x in range(COLS):
pr, pg, pb = 0, 0, 0
for y in range(ROWS):
r = randrange(100, 256)
g = randrange(100, 256)
b = randrange(100, 256)
matrix.SetPixel(x, y, r, g, b)
if y != 0:
matrix.SetPixel(x, y - 1, pr - 50, pg - 50, pb - 50)
pr, pg, pb = r, g, b
time.sleep(0.01)
while True:
rand_fill()
#fill(255, 5, 150)
drop_fill()
rainbow_fill()
#show_image('image/kc.png')