-
Notifications
You must be signed in to change notification settings - Fork 0
/
fakeneopixel.py
44 lines (33 loc) · 1.11 KB
/
fakeneopixel.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
""" Simulates the NeoPixel as image for local debugging """
from PIL import Image
import time
IMAGE_HEIGHT = 1000
class NeoPixel:
def __init__(self, num_pixels=0):
self.num_pixels = num_pixels
self.image_index = 0
self.reset()
def init_buffer(self):
self.buffer = [(0, 0, 0)] * self.num_pixels
def __setitem__(self, key, value):
assert isinstance(key, int)
assert isinstance(value, tuple)
assert len(value) == 3
self.buffer[key] = value
def show(self):
time.sleep(0.01)
for x in range(0, self.num_pixels):
self.image.putpixel((x, self.y), self.buffer[x])
self.y += 1
if self.y >= IMAGE_HEIGHT:
self.save("/tmp/image_%d.jpg" % self.image_index)
self.image_index += 1
self.reset()
def save(self, path):
output = open(path, "w")
self.image.save(output, quality=90)
print("Saving to %s" % path)
def reset(self):
self.y = 0
self.image = Image.new(mode='RGB', size=(self.num_pixels, IMAGE_HEIGHT))
self.init_buffer()