擅长:python、mysql、java
<p>在表中创建颜色列表(我称之为颜色)。
按你所询问的r,g,b点的距离来排序
列表中的第一个元素是最接近的颜色</p>
<pre><code>def distance(c1, c2):
(r1,g1,b1) = c1
(r2,g2,b2) = c2
return math.sqrt((r1 - r2)**2 + (g1 - g2) ** 2 + (b1 - b2) **2)
colors = list(rgb_code_dictionary.keys())
closest_colors = sorted(colors, key=lambda color: distance(color, point))
closest_color = closest_colors[0]
code = rgb_code_dictionary[closest_color]
</code></pre>