1

我正在尝试创建一个函数,该函数将采用 0 和 1 之间的标准化值并返回红色和蓝色之间的颜色值(彩虹色图)。见创建链接

    def normPoint(self,level):
        return .02222*level+2.4444
    def createLink (self, output_level):
        cdict = {'red': ((0., 1, 1),
                 (0.05, 1, 1),
                 (0.11, 0, 0),
                 (0.66, 1, 1),
                 (0.89, 1, 1),
                 (1, 0.5, 0.5)),
         'green': ((0., 1, 1),
                   (0.05, 1, 1),
                   (0.11, 0, 0),
                   (0.375, 1, 1),
                   (0.64, 1, 1),
                   (0.91, 0, 0),
                   (1, 0, 0)),
         'blue': ((0., 1, 1),
                  (0.05, 1, 1),
                  (0.11, 1, 1),
                  (0.34, 1, 1),
                  (0.65, 0, 0),
                  (1, 0, 0))}
        cmap = LinearSegmentedColormap('color_map', cdict,256)
        color_value = self.normPoint(output_level)
        color = self.get_color_name(cmap(color_value))
        print color, color_value
    def closest_color(self,requested_color):
        min_colors = {} 
        for key, name in webcolors.css3_hex_to_names.items():
            r_c, g_c, b_c = webcolors.hex_to_rgb(key)
            rd = (r_c - requested_color[0]) ** 2
            gd = (g_c - requested_color[1]) ** 2
            bd = (b_c - requested_color[2]) ** 2
            min_colors[(rd + gd + bd)] = name
        return min_colors[min(min_colors.keys())]
4

0 回答 0