-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.py
112 lines (94 loc) · 1.86 KB
/
Color.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
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
#!/usr/bin/python
class Color:
def __init__(self):
self.r = 0
self.g = 0
self.b = 0
self.w = 0
self.previousR = 0
self.previousG = 0
self.previousB = 0
self.previousW = 0
pass
def saveOldColors(self):
self.previousR = self.r
self.previousG = self.g
self.previousB = self.b
self.previousW = self.w
def setColorRBGW(self, r, g, b, w):
self.saveOldColors()
if(r>255):
self.r = 255
elif(r<0):
self.r = 0
else:
self.r = r
if(g>255):
self.g = 255
elif(g<0):
self.g = 0
else:
self.g = g
if(b>255):
self.b = 255
elif(b<0):
self.b = 0
else:
self.b = b
if(w>255):
self.w = 255
elif(w<0):
self.w = 0
else:
self.w = w
def getRGBW(self):
return [self.r,self.g,self.b,self.w]
def invert(self):
self.r = 255 - self.r
self.g = 255 - self.g
self.b = 255 - self.b
self.w = 255 - self.w
def getInvertedRGBW(self):
return [255 - self.r, 255 - self.g, 255 - self.b, 255 - self.w]
def getPreviousRGBW(self):
return [self.previousR,self.previousG,self.previousB,self.previousW]
def printDebug(self):
print("r: "+str(self.r))
print("g: "+str(self.g))
print("b: "+str(self.b))
print("w: "+str(self.w))
print("\n")
pass
# TODO: colors in hsl
# def setColorHLS(h,l,s):
# saveOldColors()
# self.r = r
# self.g = g
# self.b = b
# self.w = w
#
# def setColorHLSW(h,l,s,w):
# saveOldColors()
# self.r = r
# self.g = g
# self.b = b
# self.w = w
#
# def getPreviousHSL():
# return [r,g,b,w]
#
# def getPreviousHSLW():
# return [r,g,b,w]
#
# def getBitString():
# return Bitstring
#
def encodeColor(self):
# Takes 8 bits of each color (0-255) and packs it into the four bytes
# needed by the LED controller
rv = bytearray(4)
rv[0] = 0b11111111 & self.r
rv[1] = 0b11111111 & self.g
rv[2] = 0b11111111 & self.b
rv[3] = 0b11111111 & self.w
return rv