-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleColor.py
56 lines (38 loc) · 1.01 KB
/
handleColor.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
from random import randint
import json
import ioUtils
import findBestFit
colorTTL = 1000
def requestColor():
currentColor = createColor()
# graphPoints()
return currentColor
def createColor():
r = randint(0, 255)
g = randint(0, 255)
b = randint(0, 255)
return [r, g, b]
def colorCompact(RGB):
color = RGB[0]
color = color << 8
color += RGB[1]
color = color << 8
color += RGB[2]
return color
def colorDecompact(compacted):
color = [compacted % 256]
compacted = compacted >> 8
color.append(compacted % 256)
compacted = compacted >> 8
color.append(compacted)
return color[::-1]
def colorToText(color):
return "#" + ''.join("{:02X}".format(a) for a in color)
def learnColor(color, RGB):
ioUtils.decTTLs()
learned = ioUtils.getLearned()
learned[color].append([colorCompact(RGB), colorTTL])
ioUtils.setLearned(learned)
def requestBestFit(currentColor):
return findBestFit.findBestFit(currentColor)
requestBestFit((255, 0, 0))