Example #1
0
def getTextColorHex(color):
    a = 1 - ( 0.299 * color.r*255.0 + 0.587 * color.g*255.0 + 0.114 * color.b*255.0)/255.0;
    print a
    if a<0.5:
        return colors.hex("#000000")
    else:
        return colors.hex("#FFFFFF")
Example #2
0
def write_color_theme():
    theme_main_color = colors.hex(get_value(config, "COLOR_THEME"))
    action_primary_color = colors.hex(get_value(config,
                                                "COLOR_ACTION_PRIMARY"))
    action_secondary_color = colors.hex(
        get_value(config, "COLOR_ACTION_SECONDARY"))
    textColor = colors.hex(get_value(config, "COLOR_TEXT"))
    textActionColor = colors.hex(get_value(config, "COLOR_ACTION_TEXT"))
    bgColor = getLighterShadeColor(theme_main_color)
    for type in ['/release', '/debug']:
        f = open(types + type + src_package + "/colors.xml", "w")
        f.writelines("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
        f.writelines("<resources>\n")
        f.writelines("<color name=\"%s\">%s</color>\n" %
                     ("primary_color", theme_main_color.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" %
                     ("action_primary_color", action_primary_color.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" %
                     ("action_secondary_color", action_secondary_color.hex))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" %
                     ("text_color", textColor.hex[1:]))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" %
                     ("text_action_color", textActionColor.hex[1:]))
        f.writelines("<color name=\"%s\">%s</color>\n" %
                     ("bg_color", bgColor.hex))
        f.writelines("</resources>\n")
        f.close()
Example #3
0
def getTextColorHex(color):
    a = 1 - (0.299 * color.r * 255.0 + 0.587 * color.g * 255.0 +
             0.114 * color.b * 255.0) / 255.0
    print a
    if a < 0.5:
        return colors.hex("#000000")
    else:
        return colors.hex("#FFFFFF")
Example #4
0
def write_color_theme():
    color_primary = colors.hex(get_value(config, "COLOR_PRIMARY"))
    color_primary_dark = colors.hex(get_value(config, "COLOR_PRIMARY_DARK"))
    color_accent = colors.hex(get_value(config, "COLOR_ACCENT"))
    color_primary_text = colors.hex(get_value(config, "COLOR_PRIMARY_TEXT"))
    color_secondary_text = colors.hex(get_value(config, "COLOR_SECONDARY_TEXT"))
    color_icon_on_primary = colors.hex(get_value(config, "COLOR_ICON_ON_PRIMARY"))
    color_divider = colors.hex(get_value(config, "COLOR_DIVIDER"))
    color_text_on_primary = colors.hex(get_value(config, "COLOR_TEXT_ON_PRIMARY"))

    for type in ['/release', '/debug']:
        f = open(types + type + src_package + "/colors.xml", "w")
        f.writelines("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
        f.writelines("<resources>\n")
        f.writelines("<color name=\"%s\">%s</color>\n" % ("primary", color_primary.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("primary_dark", color_primary_dark.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("accent", color_accent.hex))
        f.writelines("<color name=\"%s\">#88%s</color>\n" % ("trans_accent", color_accent.hex[1:]))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" % ("primary_text", color_primary_text.hex[1:]))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" % ("secondary_text", color_secondary_text.hex[1:]))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("icons_on_primary", color_icon_on_primary.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("divider", color_divider.hex))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" % ("text_on_primary", color_text_on_primary.hex[1:]))
        f.writelines("</resources>\n")
        f.close()
    def activate(self, leaf):
        leaf_text = kupferstring.tolocale(leaf.object)
        color = leaf_text[1:]
        result = "None"
        if len(color) == 3:
            r = color[0] + color[0]
            g = color[1] + color[1]
            b = color[2] + color[2]
        elif len(color) == 6:
            r = color[0:2]
            g = color[2:4]
            b = color[4:6]
        else:
            return TextLeaf("Unknown color format")

        color = colors.hex("#" + r + g + b)
        complement = colors.complementary(color)[4]
        r = int(complement.r * 255)
        g = int(complement.g * 255)
        b = int(complement.b * 255)

        r = '%02x' % r
        g = '%02x' % g
        b = '%02x' % b

        result = "#" + str(r) + str(g) + str(b)

        return TextLeaf(result)
Example #6
0
async def to_rgb(channel, color_type, color):
    color_type = color_type.lower()
    if color_type == 'rgb':
        try:
            color = color.replace(' ', '').replace('(',
                                                   '').replace(')',
                                                               '').split(',')
            r = int(round(float(color[0])))
            g = int(round(float(color[1])))
            b = int(round(float(color[2])))
        except:
            await bot.send_message(channel, "Wrong **rgb** format!")
    elif color_type == "hex":
        try:
            color = color.replace('#', '')
            r, g, b = hex(color).rgb
        except:
            await bot.send_message(channel, "Wrong **hex** format!")
    elif color_type == 'hsv':
        try:
            color = color.replace(' ', '').replace('%',
                                                   '').replace('°',
                                                               '').split(',')
            h = float(color[0]) / 360
            s = float(color[1]) / 100
            v = float(color[2]) / 100
            r, g, b = hsv(h, s, v).rgb
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **hsv** format!")
    elif color_type == 'yiq':
        try:
            color = color.replace(' ', '').split(',')
            y = float(color[0]) * 255
            i = float(color[1]) * 255
            q = float(color[2]) * 255
            r, g, b = yiq_to_rgb(y, i, q)
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **yiq** format!")
    elif color_type == 'cmyk':
        try:
            color = color.replace(' ', '').replace('%', '').split(',')
            c = float(color[0]) / 100
            m = float(color[1]) / 100
            y = float(color[2]) / 100
            k = float(color[3]) / 100
            r, g, b = cmyk_to_rgb(c, m, y, k)
            r, g, b = int(round(r)), int(round(g)), int(round(b))
        except:
            await bot.send_message(channel, "Wrong **cmyk** format!")
    elif color_type == "name":
        try:
            r, g, b = webcolors.name_to_rgb(color)
        except:
            await bot.send_message(channel, "Wrong **color** name!")
    try:
        return r, g, b
    except:
        return -1, -1, -1
Example #7
0
def RGB_thread():
    global shared_rgb
    print("In RGB_Thread")
    screen_init()

    while True:
        print("Shared RGB Array: ", shared_rgb)
        count = len(shared_rgb)
        if (count < 3):
            print("not enough commas")
        else:
            x = shared_rgb[0]
            y = shared_rgb[1]
            hex_color = shared_rgb[2]
            print("X coord: ", x)
            print("Y Coord: ", y)
            print("Hex Color: ", hex_color)
            time.sleep(7)
            rgb_tuple = tuple(hex(hex_color).rgb)
            if (rgb_tuple.count() == 1):
                set_pixel(x, y, rgb_tuple[0], rgb_tuple[1], brgb_tuple[2])
                #clear array, need to watch out if other thread can be f****d by this
                shared_rgb = []
            else:
                print("Tuple count is not righ!")
	def activate(self, leaf):
		leaf_text = kupferstring.tolocale(leaf.object)
		color = leaf_text[1:]
		result = "None"
		if len(color) == 3:
			r = color[0] + color[0]
			g = color[1] + color[1]
			b = color[2] + color[2]
		elif len(color) == 6:
			r = color[0:2]
			g = color[2:4]
			b = color[4:6]
		else:
			return TextLeaf("Unknown color format")


		color = colors.hex("#"+r+g+b)
		complement = colors.complementary(color)[4]
		r = int(complement.r*255)
		g = int(complement.g*255)
		b = int(complement.b*255)

		r = '%02x'%r
		g = '%02x'%g
		b = '%02x'%b

		result = "#" + str(r) + str(g) + str(b)

		return TextLeaf(result)
Example #9
0
def write_color_theme():
    theme_main_color = colors.hex(get_value(config,"COLOR_THEME"))
    action_primary_color = colors.hex(get_value(config,"COLOR_ACTION_PRIMARY"))
    action_secondary_color = colors.hex(get_value(config,"COLOR_ACTION_SECONDARY"))
    textColor= colors.hex(get_value(config,"COLOR_TEXT"))
    textActionColor= colors.hex(get_value(config,"COLOR_ACTION_TEXT"))
    bgColor = getLighterShadeColor(theme_main_color)
    for type in ['/release','/debug']:
        f = open(types + type + src_package + "/colors.xml", "w")
        f.writelines("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
        f.writelines("<resources>\n")
        f.writelines("<color name=\"%s\">%s</color>\n" % ("primary_color",theme_main_color.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("action_primary_color",action_primary_color.hex))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("action_secondary_color",action_secondary_color.hex))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" % ("text_color",textColor.hex[1:]))
        f.writelines("<color name=\"%s\">#D9%s</color>\n" % ("text_action_color",textActionColor.hex[1:]))
        f.writelines("<color name=\"%s\">%s</color>\n" % ("bg_color",bgColor.hex))
        f.writelines("</resources>\n")
        f.close()
Example #10
0
def color_avatar_discover(user_color):
	value_min = 1
	colors = (
		('AB1A51'),
		('2FA1BC'),
		('5135A4'),
		('80CA57'),
		('7B3085'),
		('49C48B'),
		('485ABC'),
	)

	for color in colors:
		value = euclidean_distance(hex(color).hsv, hex(user_color).hsv)
		if value < value_min:
			value_min = value
			result = color

	return 'img/avatars/ludic/{hexadecimal}/avatar_{index}.png'.format(
		hexadecimal=result,
		index=random.randint(0, 7)
	)
Example #11
0
async def color(ctx, hexval):
    try:
        if '#' in hexval:
            hexval = hexval.translate({ord('#'): None})
        myrgb = tuple(colors.hex(hexval).rgb)
        r, g, b = myrgb[0], myrgb[1], myrgb[2]
        color_img = Image.new('RGB', (200, 200), color = (int(r), int(g), int(b)))
        color_img.save('color_img.png')
        sendimg=open('color_img.png', 'rb')
        await ctx.send(file=discord.File(sendimg, 'color.png'))
        sendimg.close()
    except:
        await ctx.send('Cannot generate picture from given hex value.')
def color_graph(agraph, colormap, blueback=False):
    for node in agraph.nodes():
        node_obj = agraph.get_node(node)
        color = colormap[node]
        inverted = str(colors.hex(color).invert().hex)
        node_obj.attr['style'] = 'filled'
        node_obj.attr['fillcolor'] = '#' + color
        node_obj.attr['fontcolor'] = '#' + inverted
    if blueback:
        agraph.graph_attr['bgcolor'] = '#' + str(colors.hsv(0.6, 0.8, 0.6).hex)
        for node in agraph.nodes():
            nodeobj = agraph.get_node(node)
            nodeobj.attr['penwidth'] = '0'
Example #13
0
 def modHSV(self, deltah, deltas, deltav):
     #for i in range(self.mainwindow.opts.ncolors):
     for i in range(Globals.ncolorstosave):
         n = i + 1
         col = Globals.colorshash['bg_color_' + str(n)]
         col = re.sub('#', '', col)
         colhsv = hex(col).hsv
         hue = colhsv.hue + deltah
         saturation = colhsv.saturation * deltas
         value = colhsv.value * deltav
         if hue > 1: hue = hue - 1
         if hue < 0: hue = 1 - hue
         if saturation > 1: saturation = 1
         if value > 1: value = 1
         colhexmod = '#' + str(hsv(hue, saturation, value).hex)
         Globals.colorshash['bg_color_' + str(n)] = colhexmod
     self.updateStyleSheet()
     self.mainwindow.savePalette()
     self.mainwindow.readPaletteFile()
     self.mainwindow.initUpdateResourceImgs()
     self.mainwindow.theme.updateTheme(delay=self.updateThemeDelay)
Example #14
0
 def test_hex_get_color(self):
     colors = hex('646464').rgb
     self.assertTrue(
         colors.red == 100 and colors.green == 100 and colors.blue == 100,
         "Get rgb from hex")
Example #15
0
 def test_hex_color_object(self):
     colors = hex('646464')
     self.assertTrue(
         colors.red == "64" and colors.green == "64"
         and colors.blue == "64", "hex Color object")
Example #16
0
 def test_color_subtracting_operator(self):
     self.assertTrue(
         hex('ff9999') - rgb(10, 10, 10) == rgb(245, 143, 143),
         "Subtracting color values with operator")
Example #17
0
def hex2rgb(hexa):
    return tuple(hex(hexa).rgb)
Example #18
0
 def test_color_multiplication_function(self):
     self.assertTrue(
         rgb(100, 100, 100).multiply(hsv(0, 1, 1)).hex == hex("640000"),
         "Multiply color values with function")
Example #19
0
 def test_color_addition_operator(self):
     self.assertTrue(
         hex('ff9999') + rgb(10, 10, 10) == rgb(255, 163, 163),
         "Adding color values with operator")
Example #20
0
 def test_difference(self):
     self.assertTrue(
         hex('ff9999').difference(rgb(10, 10, 10)).hex == hex("f58f8f"),
         "Difference values")
Example #21
0
 def test_screen(self):
     self.assertTrue(
         hex('ff9999').screen(rgb(10, 10, 10)).hex == hex("ff9d9d"),
         "Screen values")
Example #22
0
 def test_zero_division(self):
     with self.assertRaises(ZeroDivisionError):
         color_hex = hex('00ffff')
         color_rgb = rgb(100, 100, 100)
         color_rgb / color_hex
Example #23
0
 def test_color_dividing_function(self):
     self.assertTrue(
         hex('aaffcc').divide(rgb(10, 10, 10)) == rgb(17, 26, 20),
         "Dividing color values with function")
Example #24
0
 def test_color_dividing_operator(self):
     self.assertTrue(
         hex('ff9999') / rgb(10, 10, 10) == rgb(26, 15, 15),
         "Dividing color values with operator")
Example #25
0
 def test_color_subtracting_function(self):
     self.assertTrue(
         hex('aaffcc').subtract(rgb(10, 10, 10)) == rgb(160, 245, 194),
         "Subtracting color values with function")
Example #26
0
 def test_convert_hex_to_hsv(self):
     colors = hex('646464').hsv
     self.assertTrue(
         colors.hue == 0 and colors.saturation == 0
         and 0.3922 >= colors.value >= 0.3921, "Converting hex to hsv")
Example #27
0
 def test_converting_hex_object_to_list(self):
     colors = list(hex('646464').hsv)
     self.assertTrue(colors == [0.0, 0.0, 0.39215686274509803],
                     "Converting hex to hsv")
Example #28
0
 def test_invert(self):
     self.assertTrue(
         hex('000000').invert() == rgb(255, 255, 255), "Inverting values")
Example #29
0
            # - variables ------ #
            # ----- json datapoints ------ #
            timepoint = i["_source"]["layers"]["frame"]["frame.time_delta"]
            sizepoint = i["_source"]["layers"]["frame"]["frame.len"]
            colorpoint = i["_source"]["layers"]["eth"]["eth.dst"].split(':')
            transparencypoint = i["_source"]["layers"]["eth"]["eth.src"]
            protocol = i["_source"]["layers"]["frame"][
                "frame.coloring_rule.name"]
            tcplength = i["_source"]["layers"]["tcp"]["tcp.len"]

            # ----- colorpoint index ------ #
            firsthexsplit = colorpoint[0] + colorpoint[1] + colorpoint[2]
            secondhexsplit = colorpoint[3] + colorpoint[4] + colorpoint[5]

            # ----- make rgb index from converted hexcode ------ #
            torgb = hex(secondhexsplit).rgb
            string_rgb = str(torgb).replace(" ", "").split(',')

            # ----- variable conversions ------ #
            blendcolors = hex(firsthexsplit).screen(
                rgb(int(string_rgb[0]), int(string_rgb[1]),
                    int(string_rgb[2]))).hex

            parsecolor = "#{}{}".format(blendcolors, transparencypoint[0:2])
            # print parsecolor
            timeunit = math.ceil(float(timepoint))
            babyobject = {
                'color':
                parsecolor,
                'size': (math.floor(int(sizepoint)) +
                         (tcplen(tcplength, parsecolor))) / 55,
Example #30
0
 def test_hex(self):
     colors = hex('646464').hex
     self.assertTrue(
         colors.red == "64" and colors.green == "64"
         and colors.blue == "64", "Testing hex")
Example #31
0
def hex2rgb(rgb):
    return tuple(hex(rgb).rgb)
Example #32
0
 def test_hex_value_error_len(self):
     with self.assertRaises(ValueError):
         hex("#646464")
Example #33
0
 def test_hex_value_error_is_string(self):
     with self.assertRaises(ValueError):
         hex(646464)
Example #34
0
 def test_hex_value_error_is_valid_hex(self):
     with self.assertRaises(ValueError):
         hex("offfff")
Example #35
0
 def test_overlay(self):
     self.assertTrue(
         hex('ff9999').overlay(rgb(10, 10, 10)).hex == hex("ff9b9b"),
         "Overlay values")
Example #36
0
 def test_color_addition_function(self):
     self.assertTrue(
         hex('aaffcc').add(rgb(10, 10, 10)) == rgb(180, 255, 214),
         "Adding color values with function")