From 151fb732c82f5df8cd004167492cbdc3c18ced83 Mon Sep 17 00:00:00 2001 From: xfnw Date: Fri, 18 Dec 2020 21:09:22 -0500 Subject: [PATCH] detect nearest colors --- color.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/color.py b/color.py index cd1e963..9f9edec 100644 --- a/color.py +++ b/color.py @@ -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) +