コード例 #1
0
ファイル: settings.py プロジェクト: HoelShare/1337-Table
    def self_update(self, keys_down):
        self.last_keys_down = self.keys_down
        self.keys_down = keys_down

        self.frame = np.zeros((20, 35, 3), np.uint8) + theme["background"]
        render_text(self.get_frame(), theme["header"], theme["background"],
                    "Settings", 0, 0)
        render_text(self.get_frame(), theme["text"], theme["background"],
                    self.keys[self.index], 2, 8)
        a = "<"
        b = ">"
        if self.index == 0:
            a = " "
        if self.index == len(self.keys) - 1:
            b = " "
        render_text(self.frame, theme["elements"], theme["background"],
                    "%s      %s" % (a, b), 2, 14)

        if self.keys_down["LEFT"] and not self.last_keys_down["LEFT"]:
            if self.index > 0:
                self.index -= 1

        if self.keys_down["RIGHT"] and not self.last_keys_down["RIGHT"]:
            if self.index < len(self.keys) - 1:
                self.index += 1

        if self.keys_down["A"] and not self.last_keys_down["A"]:
            self.options[self.keys[self.index]]()

        if self.keys_down["B"] and not self.last_keys_down["B"]:
            self.parent.back()

        time.sleep(0.03)
コード例 #2
0
    def self_self_update(self, keys_down):
        self.last_keys_down = self.keys_down
        self.keys_down = keys_down

        self.frame = np.zeros((20, 35, 3), np.uint8) + theme["background"]
        render_text(self.get_frame(), theme["header"], theme["background"],
                    "Ambient", 0, 0)
        render_text(self.get_frame(), theme["text"], theme["background"],
                    self.keys[self.index], 2, 8)
        a = "<"
        b = ">"
        if self.index == 0:
            a = " "
        if self.index == len(self.keys) - 1:
            b = " "
        render_text(self.frame, theme["elements"], theme["background"],
                    "%s      %s" % (a, b), 2, 14)
        if self.keys_down["LEFT"] and not self.last_keys_down["LEFT"]:
            self.back_time = time.time()
            if self.index > 0:
                self.index -= 1

        if self.keys_down["RIGHT"] and not self.last_keys_down["RIGHT"]:
            self.back_time = time.time()
            if self.index < len(self.keys) - 1:
                self.index += 1

        if self.keys_down["A"] and not self.last_keys_down["A"]:
            if not self.keys[self.index] == "menu":
                self.active = self.games[self.keys[self.index]](self.matrix,
                                                                self)
            else:
                self.parent.back()

        if time.time() - self.back_time > self.parent.standby_timeout:
            self.parent.standby()
        else:
            tleft = time.time() - self.back_time
            if tleft > 0:
                tleft /= float(self.parent.standby_timeout)
                r = int(tleft * 255)
                g = 255 - r
                b = 0
                self.frame[18, 1] = (r, g, b)

        if self.keys_down["B"] and not self.last_keys_down["B"]:
            self.parent.back()

        time.sleep(0.05)
コード例 #3
0
ファイル: interface.py プロジェクト: cassiersg/elec-2103
grid = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [3, 3, 0, 0, 0, 3, 3, 0, 3, 3, 0, 0, 0, 3, 3],
        [3, 3, 0, 0, 0, 3, 3, 3, 3, 4, 0, 0, 0, 3, 3],
        [3, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [3, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]]
grid = bytearray(x for y in grid for x in y)

t1 = time.time()
cubes.cubes_init()
t2 = time.time()
cubes.draw_cubes(grid, cubes.n, cubes.m, 0, 1, 14, 1, 2, 20000, 0xffffff)
buf = bytearray(cubes.width * cubes.height * 4)
cubes.cubes_image_export(buf)
mask = font.render_text('a')
font.blit_mask(buf, 800, 480, mask, 100, 200, 0xff0000)
t3 = time.time()
cubes.cubes_exit()
pygame.init()
s = pygame.display.set_mode((800, 480))
s.fill((0, 0, 0))
b = s.get_buffer()
t4 = time.time()
b.write(bytes(buf))
pygame.display.flip()
t5 = time.time()

print("dt gen_grid", t1 - t0)
print("dt init_cubes", t2 - t1)
print("dt draw&recover buf", t3 - t2)