Ejemplo n.º 1
0
def randcolors(n=10):
    _colors = []
    for color_series, color_dct in COLORS.items():
        for k, v_rgb in color_dct.items():
            _colors.append(tuple([int(num) for num in v_rgb.split(',')]))
    # return [ random.choice(_colors) for i in range(n)]
    return random.sample(_colors, n)
Ejemplo n.º 2
0
def create_stuff(ID, x, y):
    name,typ,mat,val,fgcol,hp,kg,solid,push,script = STUFF[ID]
    world = rog.world()
    if fgcol == "random":
        fgcol = random.choice(list(COL.keys()))
##    tt = thing.Thing(x,y, _type=typ,name=name,color=COL[fgcol])
##    tt.mass = kg
##    tt.material=mat
##    if lo: _hp(tt, lo)
##    tt.isSolid = solid
##    if push: rog.make(tt, CANPUSH)
##    #_applyResistancesFromMaterial(tt, mat)
##    return tt
    ent = world.create_entity(
        cmp.Name(name),
        cmp.Position(x,y),
        cmp.Draw(typ, fgcol=fgcol),
        cmp.Form(mass=kg, mat=mat, val=val),
        cmp.BasicStats(hp=hp,mp=hp),
        )
    if solid:
        rog.make(ent, ISSOLID)
    if push:
        rog.add_component(ent, cmp.Pushable())
    script(ent)
    return ent
Ejemplo n.º 3
0
def get_rprompt(session: engine.Session):
    """
    Generuje podgląd gałęzi po prawej
    """
    DEF_PROMPT = "Miejsce na twój dowód".split()
    THRESHOLD = 128

    # Proof retrieval
    if session.proof:
        prompt, closed = session.getbranch_strings()
        color = COLORS.get(session.proof.branch, DEFAULT_COLOR)
    else:
        prompt = DEF_PROMPT
        closed = None
        color = DEFAULT_COLOR

    # Formatting
    to_show = []
    max_len = max((len(i) for i in prompt)) + 1
    for i in range(len(prompt)):
        spaces = max_len - len(prompt[i]) - int(log10(i + 1))
        to_show.append("".join((str(i + 1), ". ", prompt[i], " " * spaces)))

    # Adding branch closing symbol
    if closed:
        s = str(closed)
        spaces = max_len - len(s) + int(log10(i + 1)) + 3
        to_show.append(s + spaces * " ")

    # Foreground color calculating
    foreground = "#FFFFFF" if color.text_bright else "#000000"
    new = " \n ".join(to_show)
    return ptk.HTML(
        f'\n<style fg="{foreground}" bg="{color.rgb}"> {escape(new)} </style>')
Ejemplo n.º 4
0
def get_image_sticker_colors(image):
    image = cv2.resize(image, (224, 224), interpolation=cv2.INTER_CUBIC)

    stickers = []
    if image is not None:
        height, width, dep = image.shape
        size = width * height

        for (key, color) in COLORS.items():

            masks = []

            for range in color:
                masks.append(
                    cv2.inRange(image, np.array(range[0]), np.array(range[1])))

            merged_mask = masks[0]
            for mask in masks:
                merged_mask = merged_mask | mask

            _, thresh = cv2.threshold(merged_mask, 40, 255, 0)
            _, contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_NONE)

            if contours:
                c = max(contours, key=cv2.contourArea)

                if cv2.contourArea(c) > 0.015 * size:
                    stickers.append(key)

    return stickers
Ejemplo n.º 5
0
    def fadeLedCommand(self, command):
        # command[3] = number of LEDs being addressed.  Assume 1
        self.fadeDurationMs = command[2] * 50
        self.fadeDurationMsComplete = 0
        self.targetLedColor = COLORS.tupleFromList(command[-4:])
        self.sourceLedColor = self.ledColor

        print(
            str(self.address) + " - Fade to : " + str(self.targetLedColor) +
            " over " + str(self.fadeDurationMs) + "ms")
Ejemplo n.º 6
0
    def update(self, msDelta):
        result = []

        self.timeToNextCommand = self.timeToNextCommand - msDelta

        if (self.timeToNextCommand > 0):
            time.sleep(self.timeToNextCommand / 1000)

        self.timeToNextCommand = 1000

        if self.spraying:
            for node in self.nodes:
                result.append(
                    DisplayProgram.commandFor(
                        node, 'l'.encode(),
                        [0x08] + [0x01] + COLORS.listFromTuple(COLORS.BLACK)))
                # result.append(DisplayProgram.commandFor(node, 'L'.encode(), [0x01] + COLORS.listFromTuple(COLORS.BLACK)))
                result.append(
                    DisplayProgram.commandFor(node, 'S'.encode(), [0x00]))
            self.spraying = False
        else:
            for node in self.nodes:
                result.append(
                    DisplayProgram.commandFor(
                        node, 'l'.encode(),
                        [0x08] + [0x01] + COLORS.listFromTuple(
                            self.colorSet[self.colorPosition])))
                # result.append(DisplayProgram.commandFor(node, 'L'.encode(), [0x01] + COLORS.listFromTuple(self.colorSet[self.colorPosition])))
                result.append(
                    DisplayProgram.commandFor(node, 'S'.encode(), [0x01]))
                self.colorPosition = (self.colorPosition + 1) % len(
                    self.colorSet)

            self.spraying = True

        return result
Ejemplo n.º 7
0
def print_fitnesses(fitnesses):
    print("The most probable key lengths:")

    # top sorted by fitness, but print sorted by length
    fitnesses.sort(key=itemgetter(1), reverse=True)
    top10 = fitnesses[:10]
    best_fitness = top10[0][1]
    top10.sort(key=itemgetter(0))

    fitness_sum = calculate_fitness_sum(top10)
    fmt = "{C_KEYLEN}{:" + str(len(str(max(i[0] for i in top10)))) + \
            "d}{C_RESET}: {C_PROB}{:5.1f}%{C_RESET}"

    best_colors = COLORS.copy()
    best_colors.update({
        'C_KEYLEN': C_BEST_KEYLEN,
        'C_PROB': C_BEST_PROB,
    })

    for key_length, fitness in top10:
        colors = best_colors if fitness == best_fitness else COLORS
        pct = round(100 * fitness * 1.0 / fitness_sum, 1)
        print(fmt.format(key_length, pct, **colors))
Ejemplo n.º 8
0
    def render_map(self, map, entity_fov=None):
        if entity_fov:
            for y in range(map.height):
                for x in range(map.width):
                    visible = tcod.map_is_in_fov(entity_fov, x, y)
                    wall = map.tiles[x][y].opaque
                    if visible:
                        if wall:
                            tcod.console_set_char_background(
                                self.console, x, y, COLORS.get('light_wall'),
                                tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(
                                self.console, x, y, COLORS.get('light_ground'),
                                tcod.BKGND_SET)
                        map.tiles[x][y].explored = True
                    elif map.tiles[x][y].explored:
                        if wall:
                            tcod.console_set_char_background(
                                self.console, x, y, COLORS.get('dark_wall'),
                                tcod.BKGND_SET)
                        else:
                            tcod.console_set_char_background(
                                self.console, x, y, COLORS.get('dark_ground'),
                                tcod.BKGND_SET)

        else:
            for y in range(map.height):
                for x in range(map.width):
                    wall = map.tiles[x][y].opaque
                    if wall:
                        tcod.console_set_char_background(
                            self.console, x, y, COLORS.get('light_wall'),
                            tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            self.console, x, y, COLORS.get('light_ground'),
                            tcod.BKGND_SET)

        for entity in map.entities:
            self.render_entity(entity, entity_fov)
Ejemplo n.º 9
0
    def ledCommand(self, command):
        # command[2] = number of LEDs being addressed.  Assume 1
        self.ledColor = COLORS.tupleFromList(command[-4:])

        print(str(self.address) + " - LED Color : " + str(self.ledColor))
Ejemplo n.º 10
0
# !/usr/bin/python

from colors import COLORS
from subprocess import call
from mysql.connector import connect
from terminaltables import AsciiTable

colors = COLORS()


def read_credentials(file_name):
    """
    :param file_name: this is the name of the file contains credentials
    :return: this function will return credentials
    """
    with open(file_name, 'r') as data_file:
        # start reading line by line
        data_line = data_file.read()
        data_line = data_line.split('\n')

        # create an empty dictionary to save data
        credentials = {}

        for item in data_line:
            try:
                item = item.split('=')
                credentials[item[0]] = item[1]
            except IndexError:
                pass

        return credentials