예제 #1
0
 def __init__(self, char, pos, size):
     self.char = char
     self.font = pg.font.SysFont('ubuntumono', size, 1)
     self.origsurf = self.font.render(self.char, True, rand_color())
     self.textsurf = self.origsurf.copy()
     self.alphasurf = pg.Surface(self.textsurf.get_size(), pg.SRCALPHA)
     self.alpha = 255
     self.fading = False
     self.pos = pos
예제 #2
0
 def __init__(self, char=" ", size=3, pos=(0, 0), color=None):
     self.char = char[0]
     self.font = pg.font.SysFont("ubuntumono", size, bold=1)
     self.color = color or rand_color()
     self.origsurf = self.font.render(self.char, True, self.color)
     self.textsurf = self.origsurf.copy()
     self.alphasurf = pg.Surface(self.textsurf.get_size(), pg.SRCALPHA)
     self.alpha = 255
     self.fade_speed = 0
     self.pos = pos
예제 #3
0
    def __init__(self, screen, switch_state_func):
        pg.init()
        pg.font.init()
        self.switch_state = switch_state_func
        self.screen = screen
        self.clock = pg.time.Clock()
        self.running = True
        self.char_buffer = [Character(' ', (0, 0), 3)] * 5

        # Is this a separate game?? :)
        self.part_gen = ParticleGenerator(0, 0, 1, self.screen, rand_color())
def plot_clf(indir="res/"):
    indir = utils.abs_path_dir(indir) + "/"
    algos = []
    measure = []
    with open(indir + "global.csv", "r") as filep:
        for line in filep:
            line = line.split(",")
            algos.append(line[0])
            measure.append(tuple(map(float, line[1:4])))

    n_groups = 3
    fig, ax = plt.subplots(figsize=(10, 6))

    index = np.arange(n_groups)
    bar_width = 0.2

    opacity = 0.4
    error_config = {'ecolor': '0.3'}

    color = utils.rand_color(len(algos))
    rects = {}
    offset = 0.15
    for ind, algo in enumerate(algos):
        print(ind)
        print(tuple(measure[ind]))
        rects[ind] = plt.bar(index + bar_width * ind + offset,
                             tuple(measure[ind]),
                             bar_width,
                             alpha=opacity,
                             color=color[ind],
                             label=algo)

    plt.ylabel('Scores (in %)')
    plt.xticks(index + bar_width * ind + offset,
               ('Precision', 'Recall', 'F-Measure'))
    plt.legend()
    plt.ylim(0, 1)

    # spines & axis
    ax = plt.gca()
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')

    art = []
    lgd = ax.legend(loc=9, bbox_to_anchor=(1.1, 1.), frameon=False)
    # lgd = pylab.legend(loc=9, bbox_to_anchor=(0.5, -0.1), ncol=2)
    art.append(lgd)
    # ax.legend()
    plt.tight_layout()
    img_name = "global.png"
    plt.savefig(img_name, dpi=200, additional_artists=art, bbox_inches="tight")
예제 #5
0
 def update(self):
     x, y = pg.mouse.get_pos()
     self.part_gen.reposition(x, y)
     for event in pg.event.get():
         if event.type == KEYDOWN:
             char = get_character(event.key)
             new_char = self.non_overlapping_character(char)
             self.update_char_buffer(new_char)
             self.char_buffer[0].fade_out()
         if event.type == MOUSEBUTTONDOWN:
             self.part_gen.active = True
             self.part_gen.set_color(rand_color())
         if event.type == MOUSEBUTTONUP:
             self.part_gen.active = False
             self.part_gen.clear()
     self.part_gen.update()
     self.check_quit()
예제 #6
0
 def update(self):
     x, y = pg.mouse.get_pos()
     for event in pg.event.get():
         if event.type == KEYDOWN:
             char = event.unicode.upper()
             if char == "" or char not in "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ":
                 continue
             new_char = self.non_overlapping_character(char)
             self.update_char_buffer(new_char)
         if event.type == MOUSEBUTTONDOWN:
             self.part_gen = ParticleGenerator(x, y, 1, self.screen,
                                               rand_color())
         if event.type == MOUSEBUTTONUP:
             self.part_gen = NullGenerator()
     self.fading_buffer = [c for c in self.fading_buffer if c.alpha]
     self.part_gen.update(x, y)
     self.check_quit()
예제 #7
0
 def test_rand_color(self):
     self.assertIsInstance(utils.rand_color(), tuple)