Beispiel #1
0
def main():
    """Example and test for multi-threaded terminal output
    """
    with keyboard(), Screen() as scr:

        scr.context.color = 1, 1, 1

        scr.draw.line((0, 0), (100, 0))
        threads = []
        with scr.context(color=(1, 0, 0)) as ctx:
            for i, color in enumerate(
                [(0.1, 0, 0), (0.1, 0.05, 0), (0, 0.1, 0), (0, 0.1, 0.1), (0.1, 0, 0.1)]
            ):
                threads.append(
                    threading.Thread(target=worker, args=(scr, i * 20, color, 5))
                )
                threads[-1].start()
                time.sleep(1 / 10)

        for t in threads:
            t.join()
        scr.draw.line((0, 13), (100, 13))

        while True:
            key = inkey()
            if key == "\x1b":
                break
            time.sleep(1 / 30)
Beispiel #2
0
def iterate(sc):
    with TM.keyboard():
        while True:
            if TM.inkey() == K.ESC:
                break
            sc.update()
            time.sleep(0.1)
Beispiel #3
0
def main():
    """Example for drawing straight lines with the API, using the 1/4 block resolution.
    """
    with keyboard(), Screen() as scr:
        test_lines(scr.high)
        while True:
            if inkey() == "\x1b":
                break
Beispiel #4
0
def main():
    """Terminedia snake-game!"""

    snake = Snake((2, 2), direction=D.RIGHT)

    with terminedia.Screen() as scr, terminedia.keyboard():
        try:
            game = Game(scr, snake)
            game.run()
        except GameOver:
            pass

    print("Você bateu!\n\n")
Beispiel #5
0
def main(resolution):
    """Terminedia snake-game!"""

    snake = Snake((2, 2), direction=D.RIGHT)

    with terminedia.Screen() as scr, terminedia.keyboard():
        try:
            game = Game(scr, snake, resolution=resolution)
            game.run()
        except GameOver:
            pass

    print("You died!\n\n")
Beispiel #6
0
def vitoria(vencedor):
        if (vencedor == 'empate'):
            print('\n\n Empate.')
        else:
            print('\n\n' + COLOR + vencedor + RESETCOLOR + ' ganhou!')



posicoes = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
cursorX = 0
cursorY = 0
rodada = 1 

while (rodada > 0):
    posicoes[cursorY][cursorX] = '▮'
    tabuleiro()
    time.sleep(FPS)
    posicoes[cursorY][cursorX] = ' '
    tabuleiro()
    time.sleep(FPS)

    with TM.keyboard():
        key = TM.inkey()

        if (key == SELECT):
            cursorX, cursorY, rodada = jogada(cursorX, cursorY, rodada)        
        else: 
            cursorX, cursorY = controle(key, cursorX, cursorY, posicoes)

tabuleiro()
Beispiel #7
0
def main(shape, resolution=None, clear=False, cycle=False):
    """Quick example to navigate an string-defined shape through
    the terminal using the arrow keys! Press <ESC> to exit.


    Usage example:
    $ terminedia-shapes --custom="     \\n *** \\n * * \\n *** "

    """
    # Work around apparent bug in click:
    if shape is None:
        shape = shape1
    if "\\n" in shape:
        shape = shape.replace("\\n", "\n")
    original_shape = shape
    shape = TM.shape(
        original_shape,
        **({
            "color_map": c_map
        } if original_shape == shape2 else {}))

    shape = TM.FullShape.promote(shape, resolution=resolution)

    last_frame = time.time()
    time_acumulator = 0
    counter = 0

    def cycle_color(foreground, tick):
        if foreground != TM.DEFAULT_FG:
            return foreground
        return TM.Color(["red", "blue", "yellow", "lime"][tick % 4])

    try:

        with keyboard(), Screen(clear_screen=clear) as scr:
            # with Screen(clear_screen=True) as scr:

            x = scr.get_size()[0] // 2 - 6
            y = 0
            pos = V2(x, y)
            sprite = scr.data.sprites.add(shape, pos, active=True)
            if cycle:
                sprite.transformers.append(
                    TM.Transformer(foreground=cycle_color))

            while True:
                key = inkey()
                if key in (K.ESC, "q"):
                    break
                if not clear and key in (K.RIGHT, K.LEFT, K.UP, K.DOWN):
                    scr.data.draw.rect(sprite.rect, erase=True)
                sprite.pos += (
                    ((key == K.RIGHT) - (key == K.LEFT)),
                    ((key == K.DOWN) - (key == K.UP)),
                )

                scr.update()
                current = time.time()
                ellapsed = current - last_frame
                time_acumulator += ellapsed
                counter += 1
                pause_time = max(FRAME_DELAY - ellapsed, 0)
                time.sleep(pause_time)
                last_frame = time.time()
    finally:
        print(
            f"\nTotal frames: {counter}\nAverage time per frame: {time_acumulator / (counter or 1):.04f}"
        )
Beispiel #8
0
def main(sleep=0.2):
    """Example and benchmark tests for the drawing API using ellipses
    """
    with keyboard(), Screen() as scr:
        test_ellipses(scr, sleep)
        pause()