detect nearest colors

This commit is contained in:
xfnw 2020-12-18 21:09:22 -05:00
parent 3f7391c803
commit 151fb732c8

View file

@ -116,3 +116,12 @@ for i in EXTENDEDCOLORS:
COLORS = colors
def closestColor(rgb):
r, g, b = rgb
diss = {}
for cc in COLORS:
rc, gc, bc = COLORS[cc]
distance = abs(r-rc) + abs(g-gc) + abs(b-bc)
diss[cc] = distance
return min(diss, key=diss.get)