def setsize(self, w, h):
        def makecolor(l: list) -> int:
            return int.from_bytes(pack('=3B', *list(map(int, l))), byteorder='big')

        self.sw, self.sh, wh = w, h, w * h
        self.icon = np.zeros(wh, dtype=np.uint32)
        self.screen = np.zeros(wh, dtype=np.uint32)
        self.color_list = list(map(makecolor, cmap.colormap('Pastel1', self.nColors)))
 def colors(self, cm=None):
     try:
         _cm = cm
         if cm is None:  # random
             _cm = self.colormapNames[randint(0, len(self.colormapNames))]
         else:
             if type(cm) == int:  # by index
                 _cm = self.colormapNames[cm]
         self._colors = cmap.colormap(_cm, self.resol ** 2)
     except:
         pass
     return self._colors
Beispiel #3
0
def plot_color_gradients(cmap_category, cmap_list, nrows):

    fig, axes = plt.subplots(nrows=nrows)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
    axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

    for ax, name in zip(axes, cmap_list):
        c = cm.colormap(name)
        c = mpl.colors.ListedColormap(c, name=name, N=c.shape[0])
        ax.imshow(gradient, aspect='auto', cmap=c)
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3] / 2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    for ax in axes:
        ax.set_axis_off()

    plt.savefig(
        cmap_category.replace(' ', '_').replace('(', '').replace(
            ')', '').replace('_-_', '_') + '.png')
    plt.close()
Beispiel #4
0
def plot_color_gradients(cmap_category, cmap_list, nrows):

    fig, axes = plt.subplots(nrows=nrows)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
    axes[0].set_title(cmap_category + " colormaps", fontsize=14)

    for ax, name in zip(axes, cmap_list):
        c = cm.colormap(name)
        c = mpl.colors.ListedColormap(c, name=name, N=c.shape[0])
        ax.imshow(gradient, aspect="auto", cmap=c)
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3] / 2.0
        fig.text(x_text, y_text, name, va="center", ha="right", fontsize=10)

    for ax in axes:
        ax.set_axis_off()

    plt.savefig(
        cmap_category.replace(" ", "_").replace("(", "").replace(
            ")", "").replace("_-_", "_") + ".png")
    plt.close()
Beispiel #5
0
    "Red",
    "RedOrange",
    "RedViolet",
    "Rhodamine",
    "RoyalBlue",
    "RoyalPurple",
    "RubineRed",
    "Salmon",
    "SeaGreen",
    "Sepia",
    "SkyBlue",
    "SpringGreen",
    "Tan",
    "TealBlue",
    "Thistle",
    "Turquoise",
    "Violet",
    "VioletRed",
    "WildStrawberry",
    "Yellow",
    "YellowGreen",
    "YellowOrange")

dvips = np.array([list(cm.colormap(name, 1)[0, :]) for name in names])
jet = cm.jet(256)


idx = cm.match(dvips, jet, cm.metric.perceptual)
jdx = np.argsort(idx)
print('\n'.join([names[i] for i in jdx]))
Beispiel #6
0
    "PineGreen",
    "Plum",
    "ProcessBlue",
    "Purple",
    "RawSienna",
    "RedOrange",
    "RedViolet",
    "Rhodamine",
    "RoyalBlue",
    "RoyalPurple",
    "RubineRed",
    "Salmon",
    "SeaGreen",
    "Sepia",
    "SkyBlue",
    "SpringGreen",
    "Tan",
    "TealBlue",
    "Thistle",
    "Turquoise",
    "Violet",
    "VioletRed",
    "WildStrawberry",
    "Yellow",
    "YellowGreen",
    "YellowOrange",
]

for cmap in cmaps:
    c = cppcolormap.colormap(cmap)
Beispiel #7
0
 def setsize(self, w, h):
     self.sw, self.sh, wh = w, h, w * h
     self.icon = [0] * wh
     self.screen = [0] * wh
     self.colorlist = list(
         map(self.makecolor, cmap.colormap('Pastel2', self.colosSize)))
import cppcolormap as cmap

import matplotlib.pyplot as plt
import numpy as np

colormapNames = 'Accent,Dark2,Paired,Spectral,Pastel1,Pastel2,Set1,Set2,Set3,Blues,Greens,Greys,Oranges,Purples,Reds,BuPu,GnBu,PuBu,PuBuGn,PuRd,RdPu,OrRd,RdOrYl,YlGn,YlGnBu,YlOrRd,BrBG,PuOr,RdBu,RdGy,RdYlBu,RdYlGn,PiYG,PRGn'

# number of colors in the colormap (optional, may be omitted)
N = 128

# specify the colormap as string
cr = cmap.colormap("Reds", N)
cc = cmap.colorcycle("tue")

# or call the functions directly
c = cmap.Reds(N)
c = cmap.tue()

plt.imshow(
    np.reshape(
        cmap.colormap(colormapNames.split(',')[6], N * N) / 255., (N, N, 3)))
plt.show()
Beispiel #9
0
                setpoint(self.apcx + self.x * self.rsc,
                         self.apcy + self.y * self.rsc)
            else:
                self.k += 1

        def reshape2RGB():  # reshape self.screen from uint32 wxh to w, h, 3 RGB uint8
            return np.reshape(np.ascontiguousarray(self.screen.view(np.uint8)), (self.sw, self.sh, 4))[..., :3]

        for i in range(niters):
            iterate()

        return reshape2RGB()


if __name__ == '__main__':
    mf = 1
    w, h, niters, npreset = 1024 * mf, 1024 * mf, 90_000, 5

    print(f'generating {w:} x {h:} symmetric icon with {niters:,} iterations, type:{npreset:}')

    color_list = np.array(list(map(SymmetricIcon.makecolor, cmap.colormap('Pastel1', 2112))), dtype=np.int32)
    screen = SymmetricIcon(w, h, npreset, color_list).generate(niters)

    fig = plt.figure('symmetric icons, %d iterations ' % niters)
    ax = plt.Axes(fig, [0., 0., 1., 1.])
    ax.set_axis_off()
    fig.add_axes(ax)

    plt.imshow(screen)
    plt.show()