1

0 から 1 の間の正規化された値を取り、赤と青の間の色の値 (レインボー カラーマップ) を返す関数を作成しようとしています。createlink を参照

    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