Пример #1
0
    def test_color_transform(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        colors = [c_start, c_mid, c_stop]
        transform = lambda c: (c[0], c[1] / 2, c[2] + 100)

        palette = Palette(colors, color_transform=transform)
        palette = Palette(colors, color_transform=transform)
        for i, color in enumerate(palette):
            assert color.color_spec == transform(colors[i])
            assert color.color_model == 'hsb'
Пример #2
0
    def test_color_from_list(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        colors = [c_start, c_mid, c_stop]

        palette = Palette(colors)
        for i, color in enumerate(palette):
            assert color.color_spec == colors[i]
            assert color.color_model == 'hsb'

        palette = Palette(colors, color_model='rgb')
        for i, color in enumerate(palette):
            assert color.color_spec == colors[i]
            assert color.color_model == 'rgb'
Пример #3
0
    def test_color_from_iterable_with_names(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        colors = [c_start, c_mid, c_stop]
        names = ['mycolor1', 'col2', 'col3']
        palette = Palette((c for c in colors), color_names=names)

        for i, color in enumerate(palette):
            assert color.color_spec == colors[i]
            assert color.color_name == names[i]
Пример #4
0
    def test_palette_is_contained_in_tex_colors_at_the_end(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        color_anchors = [c_start, c_mid, c_stop]
        cmap = LinearColorMap(color_anchors=color_anchors, color_model='rgb')

        palette = Palette(cmap, color_model='rgb')
        for _, color in zip(range(3), palette):
            continue

        assert len(palette.tex_colors) == 3
Пример #5
0
    def test_from_cmap_static(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        color_anchors = [c_start, c_mid, c_stop]
        cmap = LinearColorMap(color_anchors=color_anchors, color_model='rgb')

        palette = Palette(cmap,
                          n_colors=3,
                          color_model='rgb',
                          cmap_range=(0, 1))
        for i, color in enumerate(palette):
            assert color.color_spec == color_anchors[i]

        palette = Palette(cmap,
                          n_colors=5,
                          color_model='rgb',
                          cmap_range=(0, 1))
        for color, answer in zip(palette, (c_start, (.15, .15, .15), c_mid,
                                           (.65, .65, .65), c_stop)):
            assert color.color_spec == answer
Пример #6
0
    def test_dynamic_cmap_range(self):
        c_start, c_stop = (0, 0, 0), (1, 1, 1)
        color_anchors = [c_start, c_stop]
        cmap = LinearColorMap(color_anchors=color_anchors, color_model='rgb')

        palette = Palette(cmap, color_model='rgb')
        for _, color in zip(range(3), palette):
            continue
        for color, answer in zip(palette.tex_colors, [(1 / 6, 1 / 6, 1 / 6),
                                                      (1 / 2, 1 / 2, 1 / 2),
                                                      (5 / 6, 5 / 6, 5 / 6)]):
            assert color.color_spec == answer
Пример #7
0
    def test_color_transform_with_dynamic(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        color_anchors = [c_start, c_mid, c_stop]
        cmap = LinearColorMap(color_anchors=color_anchors, color_model='rgb')

        transform = lambda c: (c[0], c[1] / 2, c[2] + 100)
        palette = Palette(cmap,
                          color_model='rgb',
                          cmap_range=(0, 1),
                          color_transform=transform)
        palette_it = iter(palette)
        assert len(palette.tex_colors) == 0
        color1 = next(palette_it)
        assert len(palette.tex_colors) == 1
        assert color1.color_spec == transform(c_start)
Пример #8
0
    def test_from_cmap_dynamic(self):
        c_start, c_mid, c_stop = (0, 0, 0), (.3, .3, .3), (1, 1, 1)
        color_anchors = [c_start, c_mid, c_stop]
        cmap = LinearColorMap(color_anchors=color_anchors, color_model='rgb')

        palette = Palette(cmap, color_model='rgb', cmap_range=(0, 1))
        palette_it = iter(palette)
        assert len(palette.tex_colors) == 0
        color1 = next(palette_it)
        assert len(palette.tex_colors) == 1
        assert color1.color_spec == c_start
        color2 = next(palette_it)
        assert len(palette.tex_colors) == 2
        assert color2.color_spec == c_stop
        color3 = next(palette_it)
        assert len(palette.tex_colors) == 3
        assert color2.color_spec == c_mid
        assert color3.color_spec == c_stop

        palette_it = iter(palette)
        next(palette_it)
        assert len(palette.tex_colors) == 1