def __init__(self, screen, npc):
   self.npc = npc
   self.screen = screen
   if isinstance(npc, characters.Monster):
       self.color = colors.get_colors('monster')
   else:
       self.color = colors.get_colors('default')
 def refresh_inner_screen(self):
     # TODO make sure the screen is big enough
         bg_color = colors.get_colors('intro_bg')
         text_color = colors.get_colors('intro_text')
         for x in range(self.inner_width):
             for y in range(self.inner_height):
                 # Same color bg/fg?
                 self.inner_window.addstr(y, x, '.', bg_color)
         self.inner_window.addstr(20, 10, 'Welcome to flaming-adventure', text_color)
    def refresh_inner_window(self):
        player = adv.app.appColl.get_player()
        # TODO make sure the window is big enough
        bg_color = colors.get_colors('intro_bg')
        text_color = colors.get_colors('intro_text')
        for x in range(self.inner_width):
            for y in range(self.inner_height):
                # Same color bg/fg?
                self.inner_window.addstr(y, x, ' ', bg_color)


        self.inner_window.addstr(10, 5, 'You have died or quit.', text_color)
        self.inner_window.addstr(12, 5, 'RIP {0}'.format(player.get_name()), text_color)
        self.inner_window.addstr(13, 5, 'Level: {0}'.format(player.get_level()), text_color)
        self.inner_window.addstr(14, 5, 'HP: {0}'.format(player.get_max_health()), text_color)
        self.inner_window.addstr(16, 5, 'Please press a key to continue/quit', text_color)
        self.inner_window.addstr(17, 5, 'q - quit', text_color)
        self.inner_window.addstr(18, 5, 'c - continue', text_color)
Example #4
0
 def __init__(self, process_count, time_slice):
     self.process_count = process_count
     self.time_slice = time_slice
     self.time = 0
     self.fig = None
     self.camera = None
     self.lines = []
     colors = get_colors()
     keys = list(colors.keys())
     random.shuffle(keys)
     self.__colors = dict([(key, colors[key]) for key in keys])
Example #5
0
def lines_chart(kxyl,
                xlabel=None,
                ylabel=None,
                title=None,
                stylecnt=3,
                verbose=False):
    '''
    create a lines chart with pre-sorted kxyl data:
        kxyl: a (key,x) sorted iterable of 4tuples having: (key, x, y, label)
            so that a line may be drawn for each key and all lines
            with same label get the same color
        xlabel: a string label for x axis
        ylabel: a string label for y axis
        title: a title for the chart
    '''
    styles, widths = ['solid', 'dashed', 'dotted'][:stylecnt], [1.5, 2,
                                                                2.5][:stylecnt]
    if title: pyplot.title(title)
    if xlabel: pyplot.xlabel(xlabel)
    if ylabel: pyplot.ylabel(ylabel)
    keylbls = {k: l for k, l in set([(k, l) for k, x, y, l in kxyl])}
    lbls = (set(l for l in keylbls.values()))
    if verbose: print('lines_chart() legend will have %d labels.' % len(lbls))
    attrs = {
        l: (clr, style, width)
        for l, clr, style, width in zip(
            sorted(lbls),
            sorted(
                get_colors(int(math.ceil(len(lbls) / float(stylecnt)))) *
                stylecnt), styles * len(lbls), widths * len(lbls))
    }
    used = {l: False for l in lbls}
    for i, (key, lbl) in enumerate(
            sorted([(k, l) for k, l in keylbls.items()], key=itemgetter(1))):
        xs = [x for k, x, y, l in kxyl if k == key]
        ys = [y for k, x, y, l in kxyl if k == key]
        clr, style, width = attrs[lbl]
        if verbose:
            print('...for %s, plotting %s with %d x,y values' %
                  (lbl, key, len(xs)))
        if not used[lbl]: used[lbl] = True
        else: lbl = None
        pyplot.plot(xs,
                    ys,
                    label=lbl,
                    color=clr,
                    linestyle=style,
                    linewidth=width)
    legend = pyplot.legend(loc=2)
    for line, text in zip(legend.get_lines(), legend.get_texts()):
        text.set_color(line.get_color())
    pyplot.show()
Example #6
0
def main():
    fn = sys.argv[1]

    img = colors.get_image(fn)
    colores = colors.get_colors(img)

    palette = colors.get_palette(colores)

    if sys.argv[2] == "1":
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(colores)
        print("\nThe palette of " + fn + " is: " + str(palette))
    elif sys.argv[2] == "0":
        print("\nThe palette of " + fn + " is: " + str(palette))
    def visualize_segments(segments, original_image):
        """
        Visualize Segments
        :param segments: (# of instances, h, w) or list of (h, w)
        :return: (h, w, 3) numpy image with colored instances
        """
        if not isinstance(segments, list):
            segments = Network.parse_merged_output(segments)

        img_h, img_w = original_image.shape[:2]
        canvas = np.zeros((img_h, img_w, 3), dtype=np.uint8)
        for idx, seg in enumerate(segments):
            r, g, b = get_colors(idx)
            canvas[:, :, 0] = canvas[:, :, 0] + b * seg[:, :]
            canvas[:, :, 1] = canvas[:, :, 1] + g * seg[:, :]
            canvas[:, :, 2] = canvas[:, :, 2] + r * seg[:, :]
        return canvas
 def __init__(self, screen, player):
   self.screen = screen
   self.player = player
   self.color = colors.get_colors('player')
 def get_sector_colors(self, str_rep):
     sector_colors = {
         '.': colors.get_colors('floor'),
         '#': colors.get_colors('wall')
     }
     return sector_colors.get(str_rep, colors.get_colors('default'))
Example #10
0
 async def send_colors(self, message):
     colors = get_colors(message.content)
     print(colors)
     files = list(map(lambda c: FileMessage(c[0], c[1]), colors))
     await self.do_send_files(message.channel, files)
Example #11
0
def show_randchart():
    '''
    displays a random chart
    '''
    print("\nEntering show_randchart()...")
    snaps = c.get_snap(True)

    loc = random.choice(locations + [None])
    type_ = random.choice(['asks', 'bids'])
    curr, country = random.choice(
        list(
            set([(x[1].curr, x[1].country) for x in c.flatten_dict(
                c.get_ads(snaps=[snaps[-1]], loc=loc, type_=type_))])))
    user = None
    #loc, type_, curr, country = '1167263622/moscow-russia-109012', 'asks',  'EUR', 'RU'
    loc, country = None, None,
    #loc, country, type_, curr = None, 'US', 'asks', 'USD'
    curr = None

    print(
        'latest show_ads() for params:loc=%s, type_=%s, curr=%s, country=%s, user=%s'
        % (loc, type_, curr, country, user))
    c.show_ads(
        c.get_ads([snaps[-1]],
                  loc=loc,
                  type_=type_,
                  user=user,
                  curr=curr,
                  country=country))

    print('gathering historic data sets for chart...')
    ads = c.get_ads(snaps,
                    loc=loc,
                    type_=type_,
                    curr=curr,
                    country=country,
                    user=user)
    print('...and done.')

    keys = sorted(
        set(['%s:%s' % (x.user, x.ad) for k, x in c.flatten_dict(ads)]))
    users = sorted(set([k.split(':')[0] for k in keys]))
    colors = {
        u.split(':')[0]: c
        for u, c in zip(users, get_colors(len(users)))
    }
    print get_colors(len(users))
    print users

    lines = {x: [] for x in keys}
    snaps = sorted(ads.keys())
    for asnap in snaps:
        samples = {x: None for x in keys}
        for aloc in [x for x in ads[asnap].keys() if x == loc or loc == None]:
            #samples.update({'%s:%s' % (x.user, x.ad): x.price for x in ads[asnap][aloc][type_]})
            samples.update({
                '%s:%s' % (x.user, x.ad): x.usd
                for x in ads[asnap][aloc][type_]
            })
        for k in keys:
            lines[k].append(samples[k])

    plt.title('%s %s %s %s' % (loc, type_, curr, country))
    for k in keys:
        user = k.split(':')[0]
        plt.plot(range(len(snaps)), lines[k], color=colors[user], label=user)
    plt.xlabel('time (15m)')
    plt.ylabel('price (%s)' % (curr))
    plt.legend(loc=2)
    #plt.legend(color='red', label='red')
    #plt.legend(color='blue', label='green')
    #plt.legend(color='green', label='green')
    plt.show()
        'cstrevex_grasiat', 'cstrevex_graiant', 'cstrevex_grnhpit',
        'cstrevex_gr2mort'
    ]
    print("Total cohort count: ", mdf.loc[:, columns].sum().sum())

    # Bar plot of completion counts & US Population
    columns = [
        'cstcball_grwhitt', 'cstcball_grhispt', 'cstcball_grbkaat',
        'cstcball_grasiat', 'cstcball_graiant', 'cstcball_grnhpit',
        'cstcball_gr2mort'
    ]
    labels = [
        'White', 'Hispanic', 'Black', 'Asian', 'Nat. Am.', 'Pac. Isl.',
        '2+ Races'
    ]
    colors = get_colors(labels, tar_color_dict)
    completions = mdf.loc[:, columns].sum(axis=0).values
    sum_completions = completions.sum()
    print("Total completions: ", sum_completions)
    census_pct = np.array([60.4, 18.3, 13.4, 5.9, 1.3, 0.2, 2.7])
    census_ct = census_pct / census_pct.sum() * sum_completions
    x_labels = ["Completions", "US Census"]
    y_label = 'Number of students'
    bars = [completions, census_ct]
    fig, ax = make_stacked_barplot(bars,
                                   x_labels=x_labels,
                                   y_label=y_label,
                                   colors=colors,
                                   stack_labels=labels,
                                   width=3)
    plt.show()