Exemple #1
0
def betagen(base_dark):

    HL_scale = 0.85
    darkscale = 0.9

    dark = base_dark

    c_dark = Color(dark)

    flag = True

    counts = 0
    new_counts = 0
    while flag:

        try:
            dark_highlight = colorscale(c_dark.hex, HL_scale)

            c = Color(dark)

            c.luminance = c.luminance * 1.7
            c.saturation = c.saturation * 0.55

            mid = c.hex

            mid_highlight = colorscale(mid, HL_scale)

            c = Color(mid)

            c.luminance = c.luminance * 1.35
            c.saturation = c.saturation * 0.95

            light = c.hex

            light_highlight = colorscale(light, HL_scale)

            flag = False
        except:
            counts += 1

            if counts < 100:

                c_dark.luminance = c_dark.luminance * 0.9

            elif new_counts < 500:

                new_counts += 1
                c_dark.luminance = c_dark.luminance * 1.1

            else:

                print(c_dark.luminance)
                print(c_dark.saturation)
                raise RuntimeError("This color sucks")

            dark = c_dark.hex

    return dark, dark_highlight, mid, mid_highlight, light, light_highlight
Exemple #2
0
def ref_to_color(ref):
    color = Color(hex=f"#{md5(ref.name.encode()).hexdigest()[2:8]}")
    if color.saturation < 0.6:
        color.saturation = 0.6
    elif color.saturation > 0.7:
        color.saturation = 0.7

    if color.luminance < 0.7:
        color.luminance = 0.7
    elif color.luminance > 0.9:
        color.luminance = 0.9
    return color.get_hex()
Exemple #3
0
def randomize_hue(bg_hex):
    color_obj = Color(bg_hex)
    randomized = random.random()
    color_obj.hue = randomized
    sat = color_obj.saturation
    color_obj.saturation = sat+randomized if (sat+randomized) <= 0.5 else 0.5
    return color_obj.get_hex()
Exemple #4
0
    async def colour(self, ctx, colour:discord.Colour):
        '''Change your colour.
        Usage: colour hex_value
        '''
        try:
            bot_channel = self.bot.get_channel(load_redis().hget(ctx.message.server.id, "botchannel").decode('utf-8'))
            r = colour.r/255
            g = colour.g/255
            b = colour.b/255
            c = Color(rgb=(r, g, b))
            if c.luminance < 0.45:
                c.luminance = 0.45
            if c.saturation > 0.80:
                c.saturation = 0.80
            colour_new = discord.Colour(int(c.hex[1:], 16))
            if colour.value != colour_new.value:
                colour = colour_new
                em = discord.Embed(description='{0} your colour has been adjusted to look better on discord. New colour: {1}'.format(ctx.message.author.mention,c.hex), colour=colour)
                await self.bot.send_message(bot_channel, embed=em)

            role = discord.utils.find(lambda r: r.name.startswith(str(ctx.message.author)), list(ctx.message.server.roles))
            em = discord.Embed(description='New color set for {0}'.format(ctx.message.author.mention), colour=colour)
            if role:
                await self.bot.edit_role(ctx.message.server,role,colour=colour)
                await self.bot.add_roles(ctx.message.author,role)
                await self.bot.send_message(bot_channel, embed=em) 
            else:
                await self.bot.create_role(ctx.message.server,name=str(ctx.message.author),colour=colour)
                await asyncio.sleep(2)
                role = discord.utils.find(lambda r: r.name.startswith(str(ctx.message.author)), list(ctx.message.server.roles))
                await self.bot.add_roles(ctx.message.author, role)
                await self.bot.send_message(bot_channel, embed=em) 
        except Exception as e:
            await self.bot.say(embed=discord.Embed(title=self.err_title, description=str(e), colour=self.colourRed))
def run(d):
    global out
    if isinstance(d, list):
        for k in d:
            if isinstance(k, dict):
                run(k)

    else:
        for k, v in d.items():
            if isinstance(v, dict) or isinstance(v, list):
                run(v)
            if isinstance(v, str) and v.startswith("#"):
                # v = v.lstrip("#")
                c = Color(v[:7])
                out += c.get_hex_l()
                if 0 < c.saturation < 1:
                    if c.luminance > 0.3:
                        c.luminance = np.clip(c.luminance + 0.1, 0, 1)
                        if c.saturation > 0:
                            c.saturation = np.clip(c.saturation + 0.2, 0, 1)
                elif c.saturation == 0:
                    if c.luminance > 0.5:
                        c.luminance = np.clip(c.luminance + 0.2, 0, 1)
                else:
                    ...
                    # c.luminance = np.clip(c.luminance + 0.05, 0, 1)

                # out = (
                #     "#"
                #     + "".join([format(int(v), "02x") for v in colorsys.hls_to_rgb(*u)])
                #     + v[6:]
                # )
                out += "\t" + c.get_hex_l() + "\n"
                d[k] = c.get_hex_l() + v[7:]
def desaturate(byte):
    #print("---------------------------------")
    #print("Byte: "+byte)
    byte = byte[2:4] + byte[0:2]  #little endian smh
    bits = bin(int(byte, scale))[2:].zfill(num_of_bits)
    r_bits = bits[1:6]
    g_bits = bits[6:11]
    b_bits = bits[11:16]
    r_convert = hex(round(int(r_bits, base=2) * inverse_ratio))[2:].zfill(2)
    g_convert = hex(round(int(g_bits, base=2) * inverse_ratio))[2:].zfill(2)
    b_convert = hex(round(int(b_bits, base=2) * inverse_ratio))[2:].zfill(2)
    rgb_str = "#" + r_convert + g_convert + b_convert
    c = Color(rgb_str)
    #print("Initial colour: "+c.get_hex())
    temp_sat = c.saturation - 0.2
    if temp_sat <= 0:
        temp_sat = 0
    c.saturation = temp_sat
    new_rgb_str = c.get_hex().replace("#", "")
    if len(new_rgb_str) == 3:
        new_rgb_str = new_rgb_str[0] + new_rgb_str[0] + new_rgb_str[
            1] + new_rgb_str[1] + new_rgb_str[2] + new_rgb_str[2]

    #print("Adjusted colour: #"+new_rgb_str)
    new_r = bin(round(int(new_rgb_str[0:2], base=16) * ratio))[2:].zfill(5)
    new_g = bin(round(int(new_rgb_str[2:4], base=16) * ratio))[2:].zfill(5)
    new_b = bin(round(int(new_rgb_str[4:6], base=16) * ratio))[2:].zfill(5)
    final_bits = "0" + new_r + new_g + new_b
    final_byte = hex(int(final_bits, base=2))[2:].zfill(4)
    final_byte = final_byte[2:4] + final_byte[0:2]
    #print("Final byte: "+final_byte)
    return final_byte
Exemple #7
0
def updatePointSpace():
    (canvas, error) = canvasDetermine(k, distType.get(), BORDER_XH - BORDER_XL,
                                      BORDER_YH - BORDER_YL, selectPoints)
    colors = colorPicker(selectPoints)

    for y in range(resolution, BORDER_YH - BORDER_YL + resolution,
                   resolution * 2):
        for x in range(resolution, BORDER_XH - BORDER_XL + resolution,
                       resolution * 2):
            try:
                color = colors[canvas[y][x]]
            except Exception:
                color = Color("#000000")
            color.saturation = (color.saturation + 1.0) / 2.0
            pointSpace.create_rectangle(x - resolution,
                                        y - resolution,
                                        x + resolution,
                                        y + resolution,
                                        fill=color)
    for point in selectPoints:
        pointX, pointY = point[0]
        pointSpace.create_rectangle(pointX - resolution * 2,
                                    pointY - resolution * 2,
                                    pointX + resolution * 2,
                                    pointY + resolution * 2,
                                    fill=colors[point[1]])
Exemple #8
0
def generate_palette(_color, _hue_variance, _saturation_variance,
                     _luminance_variance):
    base_color = Color(_color)
    palette = [base_color.hex_l]

    for i in range(1, 4):
        new_color = Color(base_color)
        new_color.hue = rotate_hue(base_color.hue, -(_hue_variance * i))
        new_color.saturation = max(
            0.0, base_color.saturation - (_saturation_variance * i))
        new_color.luminance = max(
            0.0, base_color.luminance - (_luminance_variance * i))
        palette.append(new_color.hex_l)

    for i in range(1, 4):
        new_color = Color(base_color)
        new_color.hue = rotate_hue(base_color.hue, (_hue_variance * i))
        new_color.saturation = min(
            1.0, base_color.saturation + (_saturation_variance * i))
        new_color.luminance = min(
            1.0, base_color.luminance + (_luminance_variance * i))
        palette.insert(0, new_color.hex_l)

    lighter_palette = []
    for color in palette:
        new_color = Color(color)
        new_color.hue = rotate_hue(new_color.hue, -_hue_variance / 2)
        new_color.saturation = max(
            0.0, base_color.saturation - (_saturation_variance * i))
        new_color.luminance = min(
            1.0, base_color.luminance + (_luminance_variance * i))
        lighter_palette.append(new_color.hex_l)

    darker_palette = []
    for color in palette:
        new_color = Color(color)
        new_color.hue = rotate_hue(new_color.hue, _hue_variance / 2)
        new_color.saturation = min(
            1.0, base_color.saturation + (_saturation_variance * i))
        new_color.luminance = max(
            0.0, base_color.luminance - (_luminance_variance * i))
        darker_palette.append(new_color.hex_l)

    palettes = [lighter_palette, palette, darker_palette]

    return palettes
Exemple #9
0
    def generate_background(self):
        hue_offset = promap(int(self.hash[14:][:3], 16), 0, 4095, 0, 359)
        sat_offset = int(self.hash[17:][:1], 16)
        base_color = Color(hsl=(0, .42, .41))
        base_color.hue = base_color.hue - hue_offset

        if sat_offset % 2:
            base_color.saturation = base_color.saturation + sat_offset / 100
        else:
            base_color.saturation = base_color.saturation - sat_offset / 100

        rgb = base_color.rgb
        r = int(round(rgb[0] * 255))
        g = int(round(rgb[1] * 255))
        b = int(round(rgb[2] * 255))
        return self.svg.rect(0, 0, '100%', '100%',
                             **{'fill': 'rgb({}, {}, {})'.format(r, g, b)})
Exemple #10
0
    def generate_background(self):
        hue_offset = promap(int(self.hash[14:][:3], 16), 0, 4095, 0, 359)
        sat_offset = int(self.hash[17:][:1], 16)
        base_color = Color(hsl=(0, .42, .41))
        base_color.hue = base_color.hue - hue_offset

        if sat_offset % 2:
            base_color.saturation = base_color.saturation + sat_offset / 100
        else:
            base_color.saturation = base_color.saturation - sat_offset / 100

        rgb = base_color.rgb
        r = int(round(rgb[0] * 255))
        g = int(round(rgb[1] * 255))
        b = int(round(rgb[2] * 255))
        return self.svg.rect(0, 0, '100%', '100%', **{
            'fill': 'rgb({}, {}, {})'.format(r, g, b)
        })
Exemple #11
0
    def generate_branding_style_secondary(self):
      styles = dict();

      if self.has_accent_color:
        accent = Color(self.safe_accent_color)
        accent.luminance = accent.luminance * 0.9 if accent.luminance * 0.9 >= 0 else 0;
        accent.saturation = accent.saturation * 1.1 if accent.saturation * 1.1 <= 1 else 1
        styles['background-color'] = accent.hex

      return self.css_style(styles);
Exemple #12
0
def color_for_count(count: int) -> ColorStr:
    if not count:
        return Color('white').get_hex()
    c = Color('green')
    max = 10
    count_real = min(max, count)
    c.hue = (max - count_real) / max * 0.33
    c.saturation = 1.0
    c.luminance = 0.7
    return c.get_hex()
Exemple #13
0
def get_alternate_color(color_mode, img, rgb=None):
    # Use colorgram to extract colors via K-Means clustering, pick most saturated one
    if color_mode == 'dominant':
        colors = colorgram.extract(img, 4)
        colors = sorted(colors, key=lambda c: c.hsl.s, reverse=True)
        choice = colors[0]
        return choice.rgb[0], choice.rgb[1], choice.rgb[2]

    # Modify RGB's saturation directly
    elif color_mode == 'saturated':
        rgb = rgb[0] / 255.0, rgb[1] / 255.0, rgb[2] / 255.0
        c = Color(rgb=rgb)
        c.saturation = 0.5  # User set scale here
        return int(c.rgb[0] * 255), int(c.rgb[1] * 255), int(c.rgb[2] * 255)
Exemple #14
0
def changecolour(colourcode, action, amount=100):
    c = Color(colourcode)
    if action == 'red':
        c.red = amount / 100
        return c
    elif action == 'blue':
        c.blue = amount / 100
        return c
    elif action == 'green':
        c.green = amount / 100
        return c
    elif action == 'hue':
        c.hue = amount / 100
        return c
    elif action == 'sat':
        c.saturation = amount / 100
        return c
    elif action == 'lum':
        c.luminance = amount / 100
        return c
Exemple #15
0
def twoS_twoR_colormaker(lik):
    """
    Given node likelihood, return appropriate color

    State 0 corresponds to red, state 1 corresponds to blue
    Regime 1 corresponds to grey, regime 2 corresponds to highly saturated
    """
    s0 = sum([lik[0], lik[2]])
    s1 = sum([lik[1], lik[3]])

    r0 = sum([lik[0], lik[1]])
    r1 = sum([lik[2], lik[3]])

    lum = 0.30 + (r0*0.45)

    col = Color(rgb=(0.1,s0,s1))
    col.luminance = lum
    col.saturation = 0.35 + (r1*0.35)
    col.hue *= 1 - (0.2*r0)
    return col
def color_scale(num):
    ''' Convert a number in (-1,1) to a colour.  

    Blue for negative, red for positive. '''
    positive_colour = Color("red")
    negative_colour = Color("blue")
    c = None
    if num >= 0:
        c = Color("red")
    else:
        num = num * (-1)
        c = Color("blue")

    # Clip 1 or -1 if necessary.
    if num > 1:
        num = 1
    elif num < -1:
        num = -1

    c.luminance = 1 - 0.3 * num
    c.saturation = 1
    return c.rgb
Exemple #17
0
 def add_line(self, x, y, name='plot', xerr=None, yerr=None, linewidth=0.5,
              linestyle=None, linecolor='black', legend=True, axes=None):
     if axes is None:
         axes = self.ax
     self.plotnum = self.plotnum + 1
     if name is 'plot':
         name = 'plot%d' % (self.plotnum)
     if linestyle is None:
         _ls = self.linestyle[self.plotnum % 4]
     else:
         _ls = linestyle
     if xerr is None and yerr is None:
         line = axes.plot(x, y, label=name, color=linecolor,
                          marker=self.marker[self.plotnum % 7],
                          ls=_ls, lw=linewidth, solid_capstyle='butt',
                          clip_on=True)
         for i in range(0, len(line)):
             self.lines[name + '%d' % (i)] = (line[i])
     else:
         if linecolor == 'black':
             ecolor = '#A7A9AC'
         else:
             col = Color(linecolor)
             col.saturation = 0.5
             col.luminance = 0.75
             ecolor = col.hex
         line, caplines, barlinecols = axes.errorbar(x, y, label=name,
                                                     color=linecolor,
                                                     xerr=xerr,
                                                     yerr=yerr,
                                                     marker=self.marker[self.plotnum % 7],
                                                     ls=_ls,
                                                     ecolor=ecolor,
                                                     lw=linewidth,
                                                     clip_on=True)
         self.lines[name] = (line)
     self.markers_on()
     self.lines_off()
Exemple #18
0
def plot_conjugate_conics(ax, axes, width=None, plot_foci=False, plot_inverse_hyperbola=False):
    hyp, = ax.plot(*hyperbola(axes), color='dodgerblue', label='Hyperboloid (bundle of planes)')

    # Normal vector ellipse axes lengths
    # scales inversely\ with axes but can
    # be rescaled at will

    ax1,center = __inverse_ellipse(axes)

    if plot_inverse_hyperbola:
        # Plot inverse hyperbola
        color = Color('red')
        color.saturation = 0.8
        color.luminance = 0.85
        hyp_inv, = ax.plot(*hyperbola(1/axes, opens_up=True),
                            color=str(color), zorder=-1,
                           label='Inverse hyperboloid')

    ell, = ax.plot(*ellipse(ax1, center=[0,center]), color='red',
                label='Normal vector endpoint (fixed length)')

    ax.plot(*ellipse(axes), zorder=-5, color=hyp.get_color(),alpha=0.5, linewidth=1,
            label='Variance ellipsoid')


    if plot_foci:
        # Plot hyperbola focus
        hyp_c = N.sqrt(N.sum(axes**2))
        ax.plot([0,0],[hyp_c,-hyp_c], '.', color=hyp.get_color())

        # Plot ellipse foci
        c = ax1**2
        c.sort()
        c[0] *= -1
        ell_c = N.sqrt(N.sum(c))
        # Plot ellipse foci
        ax.plot([0,0],[center+ell_c,center-ell_c], '.', color=ell.get_color())

    # Plot tangents
    xvals = N.array([-500,500])
    yvals = axes[1]/axes[0]*xvals
    kw = dict(zorder=-1, color=hyp.get_color(), linewidth=0.5)
    ax.plot(xvals, yvals, ':', **kw, label='Hyperbolic tangents')
    ax.plot(xvals, -yvals, ':', **kw)

    #yvals = axes[0]/axes[1]*xvals
    kw = dict(zorder=-1, color=ell.get_color(), linewidth=0.5)
    ax.plot(yvals, xvals, ':', **kw, label='Normal vector tangents')
    ax.plot(yvals, -xvals, ':', **kw)

    _ = 4
    if axes[1] > 0.5*axes[0]:
        _ = 6

    if width is None:
        width = N.linalg.norm(axes)*_
    lim = N.array([-width,width])/2
    ax.set_xlim(lim)
    ax.set_ylim(lim*0.6)
    ax.set_aspect(1)

    return ax