-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.py
More file actions
67 lines (57 loc) · 1.87 KB
/
Panel.py
File metadata and controls
67 lines (57 loc) · 1.87 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
import board
import neopixel
import time
import random
class Panel:
def __init__(self):
self.width = 42
self.height = 35
self.size = self.width * self.height
self.grid = None
self.initGrid()
self.brightness = 0.8
self.pixels = neopixel.NeoPixel(board.D18, self.size, auto_write=False)
def initGrid(self):
self.grid = [[0 for i in range(self.height)] for j in range(self.width)]
pixelCount = 0
colCount = 0
x = self.width - 1
while (x >= 0):
if (colCount % 2 == 0):
y = self.height - 1
while (y >= 0):
#print("Setting: " + str(x) + ", " + str(y))
self.grid[x][y] = pixelCount
pixelCount += 1
y -= 1
else:
y = 0
while (y < self.height):
self.grid[x][y] = pixelCount
pixelCount += 1
y += 1
x -= 1
colCount += 1
def getColor(self, col, brightness=-1):
b = 0
if (brightness < 0):
b = self.brightness
else:
b = brightness
return (col[1] * b, col[0] * b, col[2] * b)
def setBackground(self, col):
self.pixels.fill(self.getColor(col))
#for i in range(self.size):
#self.pixels[i] = self.getColor(col)
def setPixel(self, x, y, col, brightness=-1):
self.pixels[self.grid[x][y]] = self.getColor(col, brightness)
def show(self):
self.pixels.show()
def getMillis(self):
return int(round(time.time() * 1000))
def sideScroll(self):
while (i < self.width):
while(j < self.height):
self.pixels[self.grid[i][j]] = self.getColor(100,0,0, brightness)
i += 1
j+= 1