示例#1
0
    def __snake2(self, colour):
        matrix = np.zeros([self.width, self.height], dtype=object)
        matrix.fill(rgb2hex((0, 0, 0)))
        pixelsArray = []

        i = 0
        j = 0
        jChange = 1
        counter = 1

        matrix[i][j] = rgb2hex(colour)
        pixelsArray.append(matrix.copy().tolist())

        while counter < self.width * self.height:

            j = j + jChange
            counter = counter + 1
            matrix[i][j] = rgb2hex(colour)
            pixelsArray.append(matrix.copy().tolist())

            if j == self.height - 1 and jChange == 1:
                jChange = 0
                i = i + 1
            elif j == 0 and jChange == -1:
                jChange = 0
                i = i + 1
            elif j == self.height - 1 and jChange == 0:
                jChange = -1
            elif j == 0 and jChange == 0:
                jChange = 1

        return pixelsArray
def generate_new_theme():
    """Retrieve new theme from colormind, store in state, and apply to app."""
    if any(locked):
        # Generate only new colors for the colors that are not locked. These need to be
        # represented as "N" in the list below. Locked colors need to be represented by
        # their RGB values, e.g. [123, 123, 123].
        input_list = ["N", "N", "N", "N", "N"]
        # TODO: Refactor this.
        if locked[0]:
            if st.session_state.is_dark_theme:
                input_list[4] = utils.hex2rgb(st.session_state.backgroundColor)
            else:
                input_list[0] = utils.hex2rgb(st.session_state.backgroundColor)
        if locked[1]:
            if st.session_state.is_dark_theme:
                input_list[3] = utils.hex2rgb(
                    st.session_state.secondaryBackgroundColor)
            else:
                input_list[1] = utils.hex2rgb(
                    st.session_state.secondaryBackgroundColor)
        if locked[2]:
            input_list[2] = utils.hex2rgb(st.session_state.primaryColor)
        if locked[3]:
            if st.session_state.is_dark_theme:
                input_list[0] = utils.hex2rgb(st.session_state.textColor)
            else:
                input_list[4] = utils.hex2rgb(st.session_state.textColor)
        res = requests.get("http://colormind.io/api/",
                           json={
                               "input": input_list,
                               "model": "ui"
                           })
    else:
        # Generate new colors for all colors.
        res = requests.get("http://colormind.io/api/", json={"model": "ui"})

    # Retrieve results from colormind.io and convert to hex.
    rgb_colors = res.json()["result"]
    hex_colors = [utils.rgb2hex(*rgb) for rgb in res.json()["result"]]

    # TODO: Refactor this with the stuff above.
    # Store colors in session state. This is required so that separate tabs/users can
    # have different themes. If we would apply the theme directly to `st.config`,
    # every user would see the same theme!
    if theme_type == "Light theme":
        st.session_state.primaryColor = hex_colors[2]
        st.session_state.backgroundColor = hex_colors[0]
        st.session_state.secondaryBackgroundColor = hex_colors[1]
        st.session_state.textColor = hex_colors[4]
        st.session_state.is_dark_theme = False
    else:
        st.session_state.primaryColor = hex_colors[2]
        st.session_state.backgroundColor = hex_colors[4]
        st.session_state.secondaryBackgroundColor = hex_colors[3]
        st.session_state.textColor = hex_colors[0]
        st.session_state.is_dark_theme = True
示例#3
0
    def __snake1(self, colour):
        matrix = np.zeros([self.width, self.height], dtype=object)
        matrix.fill(rgb2hex((0, 0, 0)))
        pixelsArray = []

        i = 0
        j = 0
        iChange = 0
        jChange = 1
        iCounter = 0
        jCounter = 0
        counter = 1

        matrix[i][j] = rgb2hex(colour)
        pixelsArray.append(matrix.copy().tolist())

        while counter < self.width * self.height:

            i = i + iChange
            j = j + jChange
            counter = counter + 1
            matrix[i][j] = rgb2hex(colour)
            pixelsArray.append(matrix.copy().tolist())

            if j == self.height - 1 - jCounter and jChange == 1:
                jChange = 0
                iChange = 1
            elif i == self.width - 1 - iCounter and iChange == 1:
                jChange = -1
                iChange = 0
                iCounter = iCounter + 1
            elif j == jCounter and jChange == -1:
                jChange = 0
                iChange = -1
                jCounter = jCounter + 1
            elif i == iCounter and iChange == -1:
                jChange = 1
                iChange = 0

        return pixelsArray
示例#4
0
    def _show_plot(self):
        colors = []
        occupy = []

        for k, v in self.rgb.items():
            print('%s = %d' % (k, float(v) / self.file_num))
            c = utils.rgb2hex(k)
            colors.append(c)
            occupy.append(v)
            cv2.waitKey()
            cv2.destroyAllWindows()

        plt.bar(range(len(occupy)), occupy, color=list(colors))
        plt.show()
示例#5
0
    def generate(self):

        pixelsArray = []
        matrix = np.zeros([self.width, self.height], dtype=object)
        colour = [0, 0, 0]

        for i in range(0, self.width):
            for j in range(0, self.height):
                colour = (int(colour[0]), int(colour[1]), int(colour[2]))
                matrix[i][j] = rgb2hex(colour)
                colour = np.random.uniform(low=0, high=255, size=(3))

        np.savetxt(self.filePath, matrix, fmt='%s')
        pixelsArray.append(matrix.copy().tolist())
        return pixelsArray
示例#6
0
def print_palette(fname, palette, method):
    """ Print palette colors. """
    print('\nColor palette of ' + Fore.CYAN + Style.BRIGHT +
          '{}'.format(fname) + Style.RESET_ALL + ' using ' + Fore.CYAN +
          Style.BRIGHT + '{}'.format(method) + Style.RESET_ALL + ':\n')
    table = PrettyTable([
        Fore.CYAN + Style.BRIGHT + "rgb" + Style.RESET_ALL,
        Fore.CYAN + Style.BRIGHT + "hex" + Style.RESET_ALL,
        Fore.CYAN + Style.BRIGHT + "proportion" + Style.RESET_ALL
    ],
                        padding_width=5)
    rgbs = [(np.asarray(c) * 255).astype('uint8') for c in palette.colors]
    hexs = [rgb2hex(tuple(c)) for c in rgbs]
    for rgb, h, p in zip(rgbs, hexs, palette.percent):
        table.add_row(
            ['({:3}, {:3}, {:3})'.format(*tuple(rgb)), h, '{:.2}'.format(p)])
    print table
示例#7
0
    def __convert(self, image, resolution, effect=None, columns=None):
        height, width = resolution
        pixelValues = [rgb2hex(color) for color in image.getdata()]
        pixelArray = np.array(pixelValues, dtype='str')
        pixelArray = pixelArray.reshape(height, -1)
        fullArray = pixelArray

        if columns != None:
            emptyArray = np.full(resolution, '000000')
            if effect != None and effect == 'scroll':
                fullArray = np.concatenate(
                    (emptyArray, pixelArray, emptyArray), axis=1)
                fullArray = fullArray[:, columns[0]:columns[1]]
            else:
                fullArray = np.concatenate((pixelArray, emptyArray), axis=1)
                fullArray = fullArray[:, columns[0]:columns[1]]
                fullArray = np.concatenate((fullArray, emptyArray), axis=1)

        return fullArray[:height, :width]
示例#8
0
    def __rainbow(self, parameters):

        pixelsArray = []
        increment, iterations = parameters
        state = 0
        r = 255
        g = 0
        b = 0

        for i in range(0, iterations):
            matrix = np.zeros([self.width, self.height], dtype=object)
            matrix.fill(rgb2hex((r, g, b)))

            if state == 0:
                g = g + increment
                if g > 255 - increment:
                    state = 1
            if state == 1:
                r = r - increment
                if r < increment:
                    state = 2
            if state == 2:
                b = b + increment
                if b > 255 - increment:
                    state = 3
            if state == 3:
                g = g - increment
                if g < increment:
                    state = 4
            if state == 4:
                r = r + increment
                if r > 255 - increment:
                    state = 5
            if state == 5:
                b = b - increment
                if b < increment:
                    state = 0

            pixelsArray.append(matrix.copy().tolist())

        return pixelsArray
geojson_data_n_times = geojson.FeatureCollection(features_n_times)
    
cmin_n_times = min(feature['properties']['n_times'] for feature in geojson_data['features'])
cmax_n_times = max(feature['properties']['n_times'] for feature in geojson_data['features'])
cmax_n_times = 20

print ('min and max times is %s - %s' %(cmin_n_times, cmax_n_times))

# '#FC4C02'
# create new GeoJson objects to reduce GeoJSON data sent to Folium map as layer
style_track1   = lambda x: {'color': '#a432a8', 'weight': 5}  
style_track2   = lambda x: {'color': '#11f52f', 'weight': 5} # #4e32a8 
#style_track2   = lambda x: {'color': '#11f52f', 'weight': 5}  
# cmap needs normalized data
#style_n_times = lambda x: {'color': rgb2hex(cmap((x['properties']['n_times']-cmin_n_times)/(cmax_n_times-cmin_n_times))), 'weight': 5} 
style_n_times = lambda x: {'color': rgb2hex(cmap((min(cmax_n_times,x['properties']['n_times'])   -cmin_n_times)/(cmax_n_times-cmin_n_times))), 'weight': 5} 
tooltip_n_times = folium.features.GeoJsonTooltip(fields=['n_times'], aliases=['n_times'])


#fmap = folium.Map(location = [53.545612, -113.490067], zoom_start= 10.5)
#fmap = folium.Map(location=[37.862606, -121.978372], tiles='Stamen Terrain', zoom_start=11, control_scale=True)
fmap = folium.Map(location=[37.862606, -121.978372], tiles='Stamen Terrain', zoom_start=13, control_scale=True)

# set up Folium map
#fmap = folium.Map(tiles = None, prefer_canvas=True, disable_3d=True)
#fmap = folium.Map(tiles='Stamen Terrain', prefer_canvas=True, disable_3d=True)
#fmap = folium.Map(tiles='Stamen Terrain', name='Terrain Map', location=[34.862606, -121.978372], zoom_start=10) 
# folium.TileLayer(tiles = 'Stamen Terrain', name='Terrain Map', show=True).add_to(fmap)
folium.TileLayer(tiles = 'CartoDB dark_matter', name='CartoDB', show=False).add_to(fmap)
folium.TileLayer(tiles = 'OpenStreetMap', name='OpenStreetMap', show=False).add_to(fmap)
cmap = cm.get_cmap('jet') # matplotlib colormap