Beispiel #1
0
async def color_info(ctx, color_type: str, *, color):
    """Get info about color. \n**Examples:** \ncolorinfo hex ff0000 or #ff0000\ncolorinfo name Black\ncolorinfo rgb 255, 255, 255 or (254.70,254.70,254.70)\ncolorinfo hsv 360, 100, 100 or 360,100,100\nList of colors: RGB, HEX, HSV, YIQ, CMYK, Name"""
    r, g, b = await to_rgb(ctx.message.channel, color_type, color)
    if (r, g, b) == (-1, -1, -1):
        return
    x, z = get_colour_name((r, g, b))
    c, m, yy, k = rgb_to_cmyk(r, g, b)
    h, s, v = rgb(r, g, b).hsv
    y, i, q = rgb_to_yiq(r, g, b)

    title = "Color info"
    text = """
    RGB - ``{0}``
    HEX - ``#{1}``
    HSV - ``{2}`` 
    YIQ - ``{3}``
    CMYK - ``{4}``

    Closest colour - ``{5}``
    """.format(
        str(r) + ', ' + str(g) + ', ' + str(b), str(rgb(r, g, b).hex),
        str(round(float(h * 360), 1)) + '°, ' + str(round(float(s * 100), 1)) +
        '%, ' + str(round(float(v * 100), 1)) + '%',
        str(float(round(y, 3))) + ', ' + str(float(round(i, 3))) + ', ' +
        str(float(round(q, 3))),
        str(float(round(c * 100))) + '%, ' + str(float(round(m * 100))) +
        '%, ' + str(float(round(yy * 100))) + '%, ' +
        str(float(round(k * 100))) + '% ', z)
    color = str(rgb(r, g, b).hex)
    await bot.send_message(ctx.message.channel,
                           embed=discord.Embed(title=title,
                                               description=text,
                                               color=discord.Color(
                                                   int(color, 16))))
Beispiel #2
0
async def message(channel, r, g, b, title):
    if not (r, g, b) == (-1, -1, -1):
        x, z = get_colour_name((r, g, b))
        c, m, y, k = rgb_to_cmyk(r, g, b)
        h, s, v = rgb(r, g, b).hsv
        y, i, q = rgb_to_yiq(r, g, b)

        text = """
        RGB - ``{0}``
        HEX - ``#{1}``
        HSV - ``{2}`` 
        YIQ - ``{3}``
        CMYK - ``{4}``

        Closest colour - ``{5}``
        """.format(
            str(r) + ', ' + str(g) + ', ' + str(b), str(rgb(r, g, b).hex),
            str(round(float(h * 360), 1)) + '°, ' +
            str(round(float(s * 100), 1)) + '%, ' +
            str(round(float(v * 100), 1)) + '%',
            str(float(round(y, 3))) + ', ' + str(float(round(i, 3))) + ', ' +
            str(float(round(q, 3))),
            str(float(round(c, 1))) + '%, ' + str(float(round(m, 1))) + '%, ' +
            str(float(round(y, 1))) + '%, ' + str(float(round(k, 1))) + '% ',
            z)
        color = str(rgb(r, g, b).hex)
        await bot.send_message(channel,
                               embed=discord.Embed(title=title,
                                                   description=text,
                                                   color=discord.Color(
                                                       int(color, 16))))
Beispiel #3
0
def vertical_strip(width=10,
                   height=100,
                   color=rgb(100, 100, 100),
                   subtlety=0.1):
    """
    Draws a subtle vertical gradient strip.
    """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    ctx.scale(width / 1.0, height / 1.0)

    pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0)
    pat.add_color_stop_rgba(0, cairo_color.red, cairo_color.green,
                            cairo_color.blue, 0)
    pat.add_color_stop_rgba(1, cairo_color.red, cairo_color.green,
                            cairo_color.blue, 1)

    ctx.rectangle(0, 0, 1, 1)
    ctx.set_source(pat)
    ctx.fill()

    surface.write_to_png('vertical_strip.png')
Beispiel #4
0
async def mono_color(ctx, count: int, color_type, *, color):
    """Monochromatic color"""
    r, g, b = await to_rgb(ctx.message.channel, color_type, color)
    if (r, g, b) == (-1, -1, -1):
        return
    if count == 0:
        count = 10
    elif count > 19:
        count = 19
    color = Color([r, g, b], "", "")
    color = monochromaticColor(color)
    for i in range(10):
        r = color[i][0]
        g = color[i][1]
        b = color[i][2]
        title = "Monochromatic color {0}".format(i + 1)
        text = """
        RGB - {0}
        HEX - #{1}
        """.format(
            str(r) + ', ' + str(g) + ', ' + str(b), str(rgb(r, g, b).hex))
        colorn = str(rgb(r, g, b).hex)
        await bot.send_message(ctx.message.channel,
                               embed=discord.Embed(title=title,
                                                   description=text,
                                                   color=discord.Color(
                                                       int(colorn, 16))))
Beispiel #5
0
def vertical_strip(width=10, height=100, color=rgb(100, 100, 100),
                   subtlety=0.1):
    """
    Draws a subtle vertical gradient strip.
    """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    ctx.scale(width / 1.0, height / 1.0)

    pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0)
    pat.add_color_stop_rgba(
        0,
        cairo_color.red,
        cairo_color.green,
        cairo_color.blue,
        0
    )
    pat.add_color_stop_rgba(
        1,
        cairo_color.red,
        cairo_color.green,
        cairo_color.blue,
        1
    )

    ctx.rectangle(0, 0, 1, 1)
    ctx.set_source(pat)
    ctx.fill()

    surface.write_to_png('vertical_strip.png')
Beispiel #6
0
 def test_RGBFloatColor_equality(self):
     self.assertTrue(
         rgbf(1, 1, 1) == rgb(255, 255, 255), "RGB Color object")
     self.assertTrue(
         rgbf(0.5, 0.5, 0.5) == rgb(128, 128, 128),
         "RGB Color object; docs example")
     self.assertTrue(
         rgbf(0.5, 0.5, 0.5).rgb == rgb(128, 128, 128),
         "RGB Color object; docs example #2")
Beispiel #7
0
def rectround(x, y, w, h, clr=colors.rgb(0, 0, 0), txt="", draw=True, clr2=colors.rgb(1, 1, 1)):
    """rectround
  """
    p = _ctx.rect(x, y, w, h, roundness=1)
    if txt != "":
        _ctx.fill(clr2)
        wt, ht = _ctx.textmetrics(txt)
        _ctx.text(txt, x + w / 2 - wt / 2, y + h - ht / 4)
        _ctx.fill(clr)
    return p
Beispiel #8
0
async def color_shades(ctx, countshades: int, shades: int, color_type, *,
                       color):
    """Shades of color \n **Examples:** \n colorshades 0 0 0 20, 20, 20 \n colorshades 5 20 hex #ffff00 \n if countshades, shades or color_type = 0, then this means that the var's will be set automatically. \n if countshades = 0 then countshades = 10 \n if shades = 0 then shades will be exposed by the formula. \(o-o)/ \n if type_color = 0 then type_color = rgb"""
    if countshades == 0:
        countshades = 10
    elif countshades > 30:
        await bot.send_message(ctx.message.channel, "Max shades count **30**!")
        return
    if shades == 0:
        shades = 'auto'
    if color_type == 0:
        color_type = 'rgb'
    r, g, b = await to_rgb(ctx.message.channel, color_type, color)
    if (r, g, b) == (-1, -1, -1):
        return
    if r > g and r > b:
        most = r
    elif g > r and g > b:
        most = g
    elif b > r and b > g:
        most = b
    elif r == g or g == b:
        most = g
    elif r == b:
        most = r

    if shades == 'auto':
        shades = most / countshades
        if not int(str(shades).split('.')[1]) == 0:
            shades = int(str(shades).split('.')[0]) + 1

    for num in range(1, countshades + 1, 1):
        nr, ng, nb = shade(shades * num, r, g, b)
        nr, ng, nb = round(nr), round(ng), round(nb)

        color = str(rgb(r, g, b).hex)
        title = "Shade {0}".format(num)
        text = """
        RGB - {0}
        HEX - #{1}
        """.format(
            str(nr) + ', ' + str(ng) + ', ' + str(nb),
            str(rgb(nr, ng, nb).hex))
        color = str(rgb(nr, ng, nb).hex)
        await bot.send_message(ctx.message.channel,
                               embed=discord.Embed(title=title,
                                                   description=text,
                                                   color=discord.Color(
                                                       int(color, 16))))
Beispiel #9
0
def draw_cloud(width=140, height=60, color=rgb(255, 255, 255)):
    """ Draw a cloud with the given width, height, and color. """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    # A cloud consists of 4 circles
    draw_circle(ctx, width / 3, height / 2, height / 3, cairo_color)
    draw_circle(ctx, 2 * width / 3, height / 2, height / 3, cairo_color)
    draw_circle(ctx, width / 2, height / 3, height / 3, cairo_color)
    draw_circle(ctx, width / 2, 2 * height / 3, height / 3, cairo_color)

    surface.write_to_png('cloud.png')
Beispiel #10
0
def draw_cloud(width=140, height=60, color=rgb(255, 255, 255)):
    """ Draw a cloud with the given width, height, and color. """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    # A cloud consists of 4 circles
    draw_circle(ctx, width / 3, height / 2, height / 3, cairo_color)
    draw_circle(ctx, 2 * width / 3, height / 2, height / 3, cairo_color)
    draw_circle(ctx, width / 2, height / 3, height / 3, cairo_color)
    draw_circle(ctx, width / 2, 2 * height / 3, height / 3, cairo_color)

    surface.write_to_png('cloud.png')
Beispiel #11
0
async def color_tints(ctx, counttints: int, tints: int, color_type, *, color):
    "Tints of color"
    if counttints == 0:
        counttints = 10
    elif counttints > 30:
        await bot.send_message(ctx.message.channel, "Max tints count **30**!")
        return
    if tints == 0:
        tints = 'auto'
    if color_type == 0:
        color_type = 'rgb'
    r, g, b = await to_rgb(ctx.message.channel, color_type, color)
    if (r, g, b) == (-1, -1, -1):
        return
    if r < g and r < b:
        low = r
    elif g < r and g < b:
        low = g
    elif b < r and b < g:
        low = b
    elif r == g or g == b:
        low = g
    elif r == b:
        low = r

    if tints == 'auto':
        tints = (255 - low) / counttints
        if not int(str(tints).split('.')[1]) == 0:
            tints = int(str(tints).split('.')[0]) + 1

    for num in range(1, counttints + 1, 1):
        nr, ng, nb = tint(tints * num, r, g, b)
        nr, ng, nb = round(nr), round(ng), round(nb)

        color = str(rgb(r, g, b).hex)
        title = "Tint {0}".format(num)
        text = """
        RGB - {0}
        HEX - #{1}
        """.format(
            str(nr) + ', ' + str(ng) + ', ' + str(nb),
            str(rgb(nr, ng, nb).hex))
        color = str(rgb(nr, ng, nb).hex)
        await bot.send_message(ctx.message.channel,
                               embed=discord.Embed(title=title,
                                                   description=text,
                                                   color=discord.Color(
                                                       int(color, 16))))
 def print_board(self,dot):
     for i in range(1,len(self.board[0])+1):
         rowstring = ''
         for j in range(len(self.board)):
             c = self.board[j][-i]
             if c == 2:
                 rowstring = rowstring + Board.blue + dot
             if c == 3:
                 rowstring = rowstring + Board.blue + pop
             if c == 4:
                 rowstring = rowstring + Board.yellow + dot
             if c == 5:
                 rowstring = rowstring + Board.yellow + pop
             if c == 6:
                 rowstring = rowstring + Board.red + dot
             if c == 7:
                 rowstring = rowstring + Board.red + pop
             if c == 8:
                 rowstring = rowstring + Board.green + dot
             if c == 9:
                 rowstring = rowstring + Board.green + pop
             if c == 'd':
                 rowstring = rowstring + Board.line_color + pop
             elif c == 0:
                 rowstring = rowstring + Board.purple +shade
         print(margin + rowstring + Board.purple)
     print(margin, end = '')
     for i in range(len(self.board)):
         print(Board.base_nums[i%len(Board.base_nums)], end = '')
     print(colors.rgb(250,250,250) + '\n'+margin +'\U000023C1'+  str(score) +Board.purple, end = '')
Beispiel #13
0
def print_picture(picture):
    string = ''
    for i in range(PICHEIGHT):
        for j in range(PICWIDTH):
            string = string + colors.rgb(*shade(abs(picture[i][j]))) + BLOCK
    print('\x1bc')
    print(string)
Beispiel #14
0
 def test_draw_button(self):
     buttons.draw_img_button(
         width=176,
         height=28,
         text='Please push me :)',
         color=rgb(53,166,193)
     )
     self.assertEqual(imghdr.what('button.png'), 'png')
Beispiel #15
0
def draw(size):
    color = [100, 123, 200]
    string = ''
    for i in range(size):
        color = adjust_clr(color)
        string = string + (c.rgb(color[0], color[1], color[2]) + bar())

    return string
Beispiel #16
0
async def image_palette(ctx, url, *, num: int = 5):
    """Get image color palette. \n **Examples:** \n imagepalette https://...img.png 2 """
    response = requests.get(url)
    color_thief = ColorThief((BytesIO(response.content)))
    colorn = color_thief.get_palette(color_count=num)
    for ii in range(num):
        try:
            r, g, b = await to_rgb(ctx.message.channel, 'rgb', str(colorn[ii]))
            if (r, g, b) == (-1, -1, -1):
                return
        except:
            print('endpalitra')
        if not (r, g, b) == (-1, -1, -1):
            x, z = get_colour_name((r, g, b))
            c, m, y, k = rgb_to_cmyk(r, g, b)
            h, s, v = rgb(r, g, b).hsv
            y, i, q = rgb_to_yiq(r, g, b)

            title = "Palette color info {0}".format(ii + 1)
            text = """
            RGB - ``{0}``
            HEX - ``#{1}``
            HSV - ``{2}`` 
            YIQ - ``{3}``
            CMYK - ``{4}``

            Closest colour - ``{5}``
            """.format(
                str(r) + ', ' + str(g) + ', ' + str(b), str(rgb(r, g, b).hex),
                str(round(float(h * 360), 1)) + '°, ' +
                str(round(float(s * 100), 1)) + '%, ' +
                str(round(float(v * 100), 1)) + '%',
                str(float(round(y, 3))) + ', ' + str(float(round(i, 3))) +
                ', ' + str(float(round(q, 3))),
                str(float(round(c, 1))) + '%, ' + str(float(round(m, 1))) +
                '%, ' + str(float(round(y, 1))) + '%, ' +
                str(float(round(k, 1))) + '% ', z)
            color = str(rgb(r, g, b).hex)
            await bot.send_message(ctx.message.channel,
                                   embed=discord.Embed(title=title,
                                                       description=text,
                                                       color=discord.Color(
                                                           int(color, 16))))
Beispiel #17
0
def array_picture(array):
    for i in range(len(array)):
        rowstring = ''
        for k in range(len(array[i])):
            if k > 4 and k < (len(array[i]) - 2):
                trip = array[i][k]
                rowstring = rowstring + (c.rgb(trip[0],trip[1],trip[2]) + bar)    
        if i == len(array) - 1:
            print(rowstring, end = '')
        else:
            print(rowstring)
Beispiel #18
0
def frame_string(array):
    frame = ''
    for i in range(len(array)):
        rowstring = ''
        for k in range(len(array[i])):
            if k > 4 and k < (len(array[i]) - 2):
                trip = array[i][k]
                rowstring = rowstring + (c.rgb(trip[0], trip[1], trip[2]) +
                                         bar)
        frame = frame + rowstring
    return frame
Beispiel #19
0
async def rand_color(ctx, *, content: int = 1):
    """Get random color/s"""
    def get_rand_color():
        r = randint(0, 255)
        b = randint(0, 255)
        g = randint(0, 255)
        return r, g, b

    for num in range(content):

        r, g, b = get_rand_color()
        x, z = get_colour_name((r, g, b))
        c, m, yy, k = rgb_to_cmyk(r, g, b)
        h, s, v = rgb(r, g, b).hsv
        y, i, q = rgb_to_yiq(r, g, b)

        title = "{0} Color!".format(num + 1)
        text = """
        RGB - ``{0}``
        HEX - ``#{1}``
        HSV - ``{2}`` 
        YIQ - ``{3}``
        CMYK - ``{4}``

        Closest colour - ``{5}``
        """.format(
            str(r) + ', ' + str(g) + ', ' + str(b), str(rgb(r, g, b).hex),
            str(round(float(h * 360), 1)) + '°, ' +
            str(round(float(s * 100), 1)) + '%, ' +
            str(round(float(v * 100), 1)) + '%',
            str(float(round(y, 3))) + ', ' + str(float(round(i, 3))) + ', ' +
            str(float(round(q, 3))),
            str(float(round(c * 100))) + '%, ' + str(float(round(m * 100))) +
            '%, ' + str(float(round(yy * 100))) + '%, ' +
            str(float(round(k * 100))) + '% ', z)
        color = str(rgb(r, g, b).hex)
        await bot.send_message(ctx.message.channel,
                               embed=discord.Embed(title=title,
                                                   description=text,
                                                   color=discord.Color(
                                                       int(color, 16))))
Beispiel #20
0
async def link(ctx, color_type, *, color):
    """Gives information about the color on the website www.color-hex.com \n Example: \n link cmyk 0.0%, 88.0%, 52.0%, 4.0%"""
    r, g, b = await to_rgb(ctx.message.channel, color_type, color)
    if (r, g, b) == (-1, -1, -1):
        return
    color = str(rgb(r, g, b).hex)
    await bot.send_message(
        ctx.message.channel,
        embed=discord.Embed(
            title="About color",
            description="https://www.color-hex.com/color/{0}".format(color),
            color=discord.Color(int(color, 16))))
Beispiel #21
0
def check_word(word):
    global cpm
    while 1:
        print(colors.clear_screen)
        print(colors.rgb(0, 0, 0))
        print("characters per minute: " + str(mean(cpm)) + '\n' * 4)
        print(colors.yellow)
        begin = time.time()
        test = input(str(word) + colors.cyan + '[' + '\n')
        if str(test) == str(word):
            elapsed = time.time() - begin
            cpm.append(len(test) * 60 / elapsed)
            return
Beispiel #22
0
def draw_css_button(width=200, height=50, text='This is a button', color=rgb(200,100,50)):
    """ Draws a simple CSS button. """

    # TODO: once we've decided on a scss compiler, import it at the top instead
    from scss import Scss

    # TODO: make this customizable
    css_class = 'button'
    
    html = '<a class="{0}" href="TODO">{1}</a>'.format(css_class, text)
    
    css = Scss()
    scss_str = "a.{0} {{color: red + green;}}".format(css_class)
    css.compile(scss_str)
Beispiel #23
0
def circles_pycairo(width, height, color):
    """ Implementation of circle border with PyCairo. """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    # draw a circle in the center
    ctx.new_path()
    ctx.set_source_rgb(cairo_color.red, cairo_color.green, cairo_color.blue)
    ctx.arc(width / 2, height / 2, width / 2, 0, 2 * pi)
    ctx.fill()

    surface.write_to_png('circles.png')
Beispiel #24
0
def circles_pycairo(width, height, color):
    """ Implementation of circle border with PyCairo. """

    cairo_color = color / rgb(255, 255, 255)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)

    # draw a circle in the center
    ctx.new_path()
    ctx.set_source_rgb(cairo_color.red, cairo_color.green, cairo_color.blue)
    ctx.arc(width / 2, height / 2, width / 2, 0, 2 * pi)
    ctx.fill()

    surface.write_to_png('circles.png')
Beispiel #25
0
def init(nodebox=False, ctx=None):
    if nodebox:
        # Simulate ximport
        import colors
        colors._ctx = ctx

        # "Injecting extra methods into the NodeBox Context object is
        # quite safe since the NodeBox 1 codebase is essentially frozen,
        # so the likelihood that future updates will break this is very
        # slim."
        #   -- Excerpt from Famous Last Words, vol 42.

        ctx.color = lambda r, g, b, a: colors.rgb(r, g, b, a)
        ctx.gradientfill = colors.gradientfill
        ctx.shadow = colors.shadow
        ctx.noshadow = colors.noshadow
Beispiel #26
0
def times(player, current_record, how_many):
    done = 0

    def ask(a):
        user_guess = ""
        while not user_guess.isnumeric():
            user_guess = input(make_string(a))
            if not user_guess.isnumeric():
               q.empty_thread().start()
               only = "numbers only please"
               print(red + f'{only:^19}')
        user_guess = int(user_guess)
        if not user_guess == a.ans:
            print(red+ progress_bar(done/how_many))
            q.fail_thread().start()
            ask(a)
    
    print(screen)
    intro = 'press enter'
    _ = input(f'{intro:^19}')
    
    length = len(player.list)

    for _ in range(how_many):
        i = random.randint(0,length-1)
        print(yellow + progress_bar(done/how_many))
        start = time.perf_counter()
        ask(player.list[i])
        finish = time.perf_counter()
        elapsed = finish - start
        Problem.update_avg(player.list[i], elapsed)
        player.list[i].count += 1 
        if player.list[i].avg < 5:
            Record.update(current_record, player.list[i])
            Problem.next_problem(player.biggest)
            player.list[i] = player.biggest
            print('replaced')
            player.mastered += 1
            q.success_thread().start()
        done += 1
    

    d = 'done'
    print(bg_rgb(210,180,110) + rgb(0,0,0) + f'{d:^19}' + clear + green)  
    print(q.frog + '-great job!' '\n' + yellow + 'practice pays off.' + '\n' +cyan +'mastered: ' + str(player.mastered) + ' facts')
    
    _ = input()
Beispiel #27
0
def draw_css_button(width=200,
                    height=50,
                    text='This is a button',
                    color=rgb(200, 100, 50)):
    """ Draws a simple CSS button. """

    # TODO: once we've decided on a scss compiler, import it at the top instead
    from scss import Scss

    # TODO: make this customizable
    css_class = 'button'

    html = '<a class="{0}" href="TODO">{1}</a>'.format(css_class, text)

    css = Scss()
    scss_str = "a.{0} {{color: red + green;}}".format(css_class)
    css.compile(scss_str)
Beispiel #28
0
def times(limit):
    done = 0
    table = []
    for i in range(2, limit):
        for j in range(i, limit):
            table.append((j, i, i + j))
    random.shuffle(table)

    full_list = len(table)

    def ask(a):
        user_guess = ""
        while not user_guess.isnumeric():
            user_guess = input(make_string(a))
            if not user_guess.isnumeric():
                q.empty_thread().start()
                only = "numbers only please"
                print(red + f'{only:^19}')
        user_guess = int(user_guess)
        if not user_guess == a[2]:
            print(red + progress_bar(done / full_list))
            q.fail_thread().start()
            ask(a)

    print(screen)
    intro = 'press enter'
    _ = input(f'{intro:^19}')
    start = time.perf_counter()
    while table:
        print(yellow + progress_bar(done / full_list))
        ask(table.pop())
        q.success_thread().start()
        done += 1
    finish = time.perf_counter()
    elapsed = round(finish - start)
    d = 'done'
    print(bg_rgb(210, 180, 110) + rgb(0, 0, 0) + f'{d:^19}' + clear + green)
    print(q.frog + '-great job!'
          '\n' + yellow + 'practice pays off.' + '\n' + cyan + 'took: ' +
          str(elapsed) + " seconds")
    _ = input()
Beispiel #29
0
def draw_img_button(width=200, height=50, text='This is a button', color=rgb(200,100,50)):
    """ Draws a simple image button. """
    
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)
    ctx.rectangle(0, 0, width - 1, height - 1)

    ctx.set_source_rgb(color.red/255.0, color.green/255.0, color.blue/255.0)
    ctx.fill()
    
    # Draw text
    ctx.set_source_rgb(1.0, 1.0, 1.0)
    ctx.select_font_face(
        "Helvetica",
        cairo.FONT_SLANT_NORMAL,
        cairo.FONT_WEIGHT_BOLD
    )
    ctx.set_font_size(15.0)
    ctx.move_to(15, 2 * height / 3)
    ctx.show_text(text)
    
    surface.write_to_png('button.png')
Beispiel #30
0
def draw_img_button(width=200,
                    height=50,
                    text='This is a button',
                    color=rgb(200, 100, 50)):
    """ Draws a simple image button. """

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(surface)
    ctx.rectangle(0, 0, width - 1, height - 1)

    ctx.set_source_rgb(color.red / 255.0, color.green / 255.0,
                       color.blue / 255.0)
    ctx.fill()

    # Draw text
    ctx.set_source_rgb(1.0, 1.0, 1.0)
    ctx.select_font_face("Helvetica", cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_BOLD)
    ctx.set_font_size(15.0)
    ctx.move_to(15, 2 * height / 3)
    ctx.show_text(text)

    surface.write_to_png('button.png')
Beispiel #31
0
    def RefreshColor(self):
        cv2.namedWindow('Set Color')
        cv2.setMouseCallback('Set Color', self.on_mouse)
        self.tmp_frame = self.UP.framethread.frame

        while True:
            # if ret == False:
            # 	break

            self.FindPos(self.tmp_frame, (0, 0))
            print("1")
            cv2.imshow('Set Color', self.tmp_frame)
            self.tmp_frame = self.DP.Result
            print("2")
            if cv2.waitKey(1) & 0xFF == ord('s'):
                cv2.destroyWindow("Set Color")
                cv2.waitKey(1)
                cv2.waitKey(1)
                cv2.waitKey(1)
                cv2.waitKey(1)
                break
        #Set label color
        self.RGB.config(
            bg='#' + str(rgb(self.Color[2], self.Color[1], self.Color[0]).hex))
Beispiel #32
0
def rgb2hex(rgb):
    return str(rgb(rgb).hex)
Beispiel #33
0
from getch import getch
import colors
import random
import time

size = 4

# stuff for printing
dot = '◉'
black = colors.rgb(0, 0, 0)
white = colors.rgb(255, 255, 255)
cyan = colors.cyan
red = colors.red
magenta = colors.rgb(250, 0, 250)
yellow = colors.yellow
frog = '☻'
block = '◯'
block = '☗'
block = '█'

print(colors.hide_cursor)


def make_grid(n):
    return [[0] * n for i in range(n)]


grid = make_grid(size)

for i in range(size):
    for j in range(size):
Beispiel #34
0
def circles(width=12, height=12, color=rgb(255, 255, 255)):
    """ Draws a repeatable circle border pattern. """

    circles_pycairo(width, height, color)
Beispiel #35
0
import random
import time
import quest as q
import sys
from colors import rgb, bg_rgb, hide_cursor

margin = '       '
cyan = rgb(50, 180, 210)
yellow = rgb(210, 180, 110)
green = rgb(50, 240, 120)
red = '\u001b[91m'
bold = '\u001b[1m'
clear = '\u001b[0m'
screen = '\033[2J'

print(hide_cursor)


def make_string(a):
    upper = a[0]
    lower = a[1]
    answer = a[2]

    uLen = len(str(upper))
    lLen = len(str(lower))
    aLen = len(str(answer))
    digits = max(uLen, lLen, aLen - 3)

    return (cyan + margin + ' ' * 2 + f'{str(upper):>{digits}}' + '\n' +
            margin + yellow + bold + '+' + clear + cyan + ' ' * 1 +
            f'{str(lower):>{digits}}' + '\n' + margin + '-' * (2 + digits) +
import slumber
from colors import rgb
import html5lib
import lxml.html
from collections import defaultdict
from lxml.html.clean import Cleaner
from lxml import etree
from urlparse import urljoin

from utils import all

SITE = "http://127.0.0.1:8000/"

# We need some hints to figure out where the info table is
COLOR_HINT = rgb(232, 236, 239)

api_endpoint = urljoin(SITE, 'api/')

api = slumber.API(api_endpoint)


def strip_html(s):
    cleaner = Cleaner(style=True)
    html = lxml.html.fromstring(s)
    return cleaner.clean_html(html).text_content()


def extract_attrs_from_table(table):
    data = {}
    # Find a td with background-color the same as our COLOR_HINT.
    # This is our rough key.
Beispiel #37
0
def getLighterShadeColor(color):
    hls = colorsys.rgb_to_hls(color.r, color.g, color.b)
    print hls[1]
    hsv2 = 0.97
    rgb = colorsys.hls_to_rgb(hls[0], hsv2, hls[2])
    return colors.rgb(rgb[0], rgb[1], rgb[2])
Beispiel #38
0
 def test_vertical_strip(self):
     gradients.vertical_strip(width=10, height=107,
                              color=rgb(255, 252, 229))
     self.assertEqual(imghdr.what('vertical_strip.png'), 'png')
Beispiel #39
0
class Board(object):
    board = []

    def __init__(self, width, height):
        self.board = [[0] * width for i in range(height)]
        self.width = width
        self.height = height

    def transform(self, d):
        h = self.height
        w = self.width
        R = Board(h, w)
        for i in range(h):
            for j in range(w):
                if d == 'r':
                    R.board[-(j + 1)][i] = self.board[i][j]
                if d == 'l':
                    R.board[j][-(i + 1)] = self.board[i][j]
                if d == 't':
                    R.board[-(j + 1)][-(i + 1)] = self.board[i][j]
                if d == 'T':
                    R.board[j][i] = self.board[i][j]
                if d == 'u':
                    R.board[i][-(j + 1)] = self.board[i][j]
                if d == 'f':
                    R.board[-(i + 1)][j] = self.board[i][j]
                if d == 'md':
                    R.board[i][(j - 1) % R.width] = self.board[i][j]
                if d == 'mu':
                    R.board[i][(j + 1) % R.width] = self.board[i][j]
                if d == 'ml':
                    R.board[(i - 1) % R.height][j] = self.board[i][j]
                if d == 'mr':
                    R.board[(i + 1) % R.height][j] = self.board[i][j]
                if d == 'ne':
                    R.board[(i + 1) % R.height][(j + 1) %
                                                R.width] = self.board[i][j]
                if d == 'nw':
                    R.board[(i - 1) % R.height][(j + 1) %
                                                R.width] = self.board[i][j]
                if d == 'se':
                    R.board[(i + 1) % R.height][(j - 1) %
                                                R.width] = self.board[i][j]
                if d == 'sw':
                    R.board[(i - 1) % R.height][(j - 1) %
                                                R.width] = self.board[i][j]
        return R

    def transform_drop(self):
        """
        The general animation function that takes 
        care of "dropping" the pieces after a board change
        """
        s = 1  #scale index for the music
        Board.print_board(self, dot)
        print(margin + Board.purple + '\n' + ' ' * 9, end='\r')
        bass = scale[:3]
        sounds.pluck(.2, 55 * random.choice(bass))
        time.sleep(.2)
        while (Board.will_drop(self) == 1):
            for row in self.board:
                for i in range(len(row) - 1):
                    if row[i] == 0 and row[i + 1] != 0:
                        row[i], row[i + 1] = row[i + 1], row[i]
            Board.print_board(self, dot)
            print(margin + Board.purple + '\n' + ' ' * 9, end='\r')
            s += 1
            sounds.play_exp(.1, scale[-s % len(scale)] * 110)
            time.sleep(.2)
        Board.print_board(self, dot)
        print(margin + Board.purple + '\n' + ' ' * 9, end='\r')
        return self

    def will_drop(self):
        """
        Checks board for whether a drop event must occur
        """
        for row in self.board:
            for i in range(len(row) - 1):
                if row[i] == 0 and row[i + 1] != 0:
                    return 1
        return 0

    def drop(self, row, mark):
        """
        Takes care of dropping a single piece
        
        Not sure if this still needs to exist
        because there is a more general drop 
        function available
        """

        for i in range(len(self.board[row]) - 1, -1, -1):

            print(margin + ' ')
            if self.board[row][i] == 0:
                self.board[row][i] = mark
                Board.print_board(self, dot)
                if i == 0 or not self.board[row][i - 1] == 0:
                    print(margin + ' ')
                    Board.print_board(self, star)
                    # i think the print method is to blame for
                    # all these extra empty print lines:
                    # theyre just to bring the cursor down a line
                    # for which i think an ansi escape would work
                    # even better

                    print(margin + Board.purple + '\n' + ' ' * 9, end='\r')
                    sounds.play_trap(.3, 220 * random.choice(scale))
                    time.sleep(0.3)
                    print(margin + ' ')
                    Board.print_board(self, dot)
                    print(margin + '\n', end='\r')
                    return self
                print(margin + Board.purple + '\n' + ' ' * 9, end='\r')
                sounds.play_trap(.1, 220 * random.choice(scale))
                time.sleep(0.2)
                self.board[row][i] = 0
        return self

    def is_four(self):
        pass

    def check_four(self):
        counter = 0
        width = len(self.board[0])
        height = len(self.board)

        # this is the global variable for how many
        # dots were deleted this round, used elsewhere
        global score
        change = 0
        to_delete = []

        # here are separate iterators for horizontal,
        # vertical and diagonal(two directions) iteration

        #verticals
        for row in range(height):
            for col in range(1, width):
                if self.board[row][col] == self.board[row][
                        col - 1] and self.board[row][col] != 0:
                    counter += 1
                    try:
                        stopping = self.board[row][col] != self.board[row][col
                                                                           + 1]
                    except IndexError:
                        stopping = True
                    if counter >= 3 and ((col == width - 1) or stopping):
                        change += 1
                        score += round(2**(counter + 1))
                        for d in range(counter + 1):
                            to_delete.append((row, col - d))
                else:
                    counter = 0
            counter = 0
        counter = 0

        #horizontals
        for col in range(width):
            for row in range(1, height):
                if self.board[row][col] == self.board[
                        row - 1][col] and self.board[row][col] != 0:
                    counter += 1
                    try:
                        stopping = self.board[row][col] != self.board[row +
                                                                      1][col]
                    except IndexError:
                        stopping = True
                    if counter >= 3 and ((row == height - 1) or stopping):
                        change += 1
                        score += round(2**(counter + 1))
                        for d in range(counter + 1):
                            to_delete.append((row - d, col))
                else:
                    counter = 0
            counter = 0
        counter = 0

        # one direction of diagonals
        for a in range(height - 3):
            for i in range(width - 3):
                for j in range(min(height - a - 1, width - i - 1)):
                    border = False
                    try:
                        self.board[a + j + 2][i + j + 2] == None
                    except IndexError:
                        border = True
                    if self.board[a + j][i + j] == self.board[a + j + 1][
                            i + 1 + j] and self.board[a + j][i + j] != 0:
                        counter += 1
                        if counter >= 3:
                            if border or (self.board[a + j + 1][i + j + 1] !=
                                          self.board[a + j + 2][i + j + 2]):
                                change += 1
                                score += round(2**(counter + 1))
                                for d in range(counter + 1):
                                    to_delete.append(
                                        (a + j + 1 - d, i + j + 1 - d))
                    else:
                        counter = 0
                counter = 0
            counter = 0
        counter = 0

        # other direction of diagonals
        for a in range(height - 3):
            for i in range(3, width):
                for j in range(min(height - a - 1, i)):
                    border = False
                    try:
                        self.board[a + j + 2][i - j - 2] == None
                    except IndexError:
                        border = True
                    if self.board[a + j][i - j] == self.board[a + j + 1][
                            i - j - 1] and self.board[a + j][i - j] != 0:
                        counter += 1
                        if counter >= 3:
                            if border or (self.board[a + j + 1][i - j - 1] !=
                                          self.board[a + j + 2][i - j - 2]):
                                change += 1
                                score += round(2**(counter + 1))
                                for d in range(counter + 1):
                                    to_delete.append(
                                        (a + j + 1 - d, i - j - 1 + d))
                    else:
                        counter = 0
                counter = 0
            counter = 0
        counter = 0

        # rectangle
        # every rectangle is made up of these 2x2 squares
        square_set = set()
        for i in range(height - 1):
            for j in range(width - 1):
                if self.board[i][j] != 0:
                    if self.board[i][j] == self.board[i + 1][j] == self.board[
                            i][j + 1] == self.board[i + 1][j + 1]:
                        square_set.add((i, j))
                        square_set.add((i + 1, j))
                        square_set.add((i, j + 1))
                        square_set.add((i + 1, j + 1))
                        change += 1
        if square_set:
            score += 2**len(square_set)
        for s in square_set:
            to_delete.append(s)

        for e in to_delete:
            self.board[e[0]][e[1]] = 'd'
        if to_delete:
            Board.print_board(self, dot)
            print(margin + ' ')
            sounds.pluck(.1, 110 * scale[0])
            sounds.pluck(.1, 110 * scale[1])
            sounds.pluck(.3, 110 * random.choice(scale))
            time.sleep(.5)
        for e in to_delete:
            self.board[e[0]][e[1]] = 0
        return (self, change > 0, score)

    def is_space(self, x):
        return self.board[x][-1] == 0

    #color scheme is very important
    blue = colors.rgb(70, 70, 200)
    yellow = colors.rgb(200, 200, 50)
    purple = colors.rgb(200, 0, 70)
    red = colors.rgb(250, 50, 150)
    green = colors.rgb(0, 100, 50)
    white = colors.rgb(255, 220, 180)
    line_color = colors.rgb(255, 255, 255)

    # these are the circled numbers under the columns
    base_nums = [
        '\U00002460',
        '\U00002461',
        '\U00002462',
        '\U00002463',
        '\U00002464',
        '\U00002465',
        '\U00002466',
        '\U00002467',
        '\U00002468',
        '\U00002469',
        '\U0000246a',
        '\U0000246b',
        '\U0000246c',
        '\U0000246d',
        '\U0000246e',
        '\U0000246f',
        '\U00002470',
        '\U00002471',
        '\U00002472',
        '\U00002473',
    ]

    def print_board(self, dot):
        for i in range(1, len(self.board[0]) + 1):
            rowstring = ''
            for j in range(len(self.board)):
                c = self.board[j][-i]
                if c == 'x':
                    rowstring = rowstring + Board.blue + dot
                if c == 'o':
                    rowstring = rowstring + Board.yellow + dot
                if c == 't':
                    rowstring = rowstring + Board.red + dot
                if c == 'u':
                    rowstring = rowstring + Board.green + dot
                if c == 'd':
                    rowstring = rowstring + Board.line_color + pop
                elif c == 0:
                    rowstring = rowstring + Board.purple + shade
            print(margin + rowstring + Board.purple)
        print(margin, end='')
        for i in range(len(self.board)):
            print(Board.base_nums[i % len(Board.base_nums)], end='')
        print(colors.rgb(250, 250, 250) + '\n' + margin + '\U000023C1' +
              str(score) + Board.purple,
              end='')
Beispiel #40
0
def getLighterShadeColor(color):
    hls = colorsys.rgb_to_hls(color.r, color.g, color.b)
    print hls[1]
    hsv2 = 0.97
    rgb = colorsys.hls_to_rgb(hls[0], hsv2, hls[2])
    return colors.rgb(rgb[0],rgb[1],rgb[2])