-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathowo-pi.py
More file actions
92 lines (75 loc) · 3.8 KB
/
owo-pi.py
File metadata and controls
92 lines (75 loc) · 3.8 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
#!/usr/bin/env python3
#Version 1.0
import numpy as np
from PIL import Image, ImageOps
from rgbmatrix import RGBMatrix, RGBMatrixOptions
# vars
matrix = None
col = [255, 0, 255] # Color of pixels
eyearray = [
[0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], # 1
]
moutharray = [
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x40, 0x02, 0x00,
0x00, 0x00, 0x00, 0x40, 0x08, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x80], # 1
]
# Functions down here
def arrayToImg(arr, width, height, col=[255, 0, 255]):
imgArray = []
if len(arr) == width*height / 8: # single-color mode
counter = 0
row = []
for byte in arr:
for i in range(8):
bit = byte >> 7-i & 1
pixel = col if bit else [0, 0, 0]
row.append(pixel)
counter += 8
if counter % width == 0:
imgArray.append(row)
row = []
else: # RGB mode
counter = 0
row = []
for i in range(int(len(arr)/3)):
r = arr[i*3]
g = arr[i*3+1]
b = arr[i*3+2]
row.append([r, g, b])
counter += 1
if counter % width == 0:
imgArray.append(row)
row = []
return Image.fromarray(np.uint8(imgArray)).convert("RGB")
def generateFace(eyeIndex, mouthIndex, width, height):
halfHeight = int(height/2)
mouthImg = arrayToImg(moutharray[mouthIndex], width, halfHeight, col)
eyeImg = arrayToImg(eyearray[eyeIndex], width, halfHeight, col)
# Create image with size of both panels
img_out = Image.new('RGB', (width, height))
# Gotta mirror one to make them face the right way
img_out.paste(mouthImg, (0, halfHeight))
img_out.paste(eyeImg, (0, 0))
return img_out
def reflectImg(img): # Reflect image so that it displays correctly on both panels
img_out = Image.new('RGB', (img.width*2, img.height))
img_out.paste(ImageOps.mirror(img), (img.width, 0))
img_out.paste(img, (0, 0))
return img_out
def init():
global matrix
options = RGBMatrixOptions()
options.rows = 32
options.cols = 64
options.chain_length = 2
options.parallel = 1
options.gpio_slowdown = 2
options.hardware_mapping = 'adafruit-hat'
matrix = RGBMatrix(options=options)
if __name__ == "__main__":
init()
img = generateFace(0, 0, 64, 32) # Generate image from states
matrix.SetImage(reflectImg(img)) # Show em
while True:
pass