Esempio n. 1
0
def main():
    t = Terminal()
    t.cursor_set_visible(False)

    # the beautiful art
    art = [
        "DDDDDDDDDVVVVVV        VVVVDDDDDDDDDD   ",
        "DDDDDDDDDDDVVVVV      VVVVVDDDDDDDDDDDD ",
        "        DDDD VVVV    VVVV           DDDD",
        "DDD      DDD  VVVV  VVVV    DDD      DDD",
        "DDD     DDDD   VVVVVVVV     DDD     DDDD",
        "DDDDDDDDDDD     VVVVVV      DDDDDDDDDDD ",
        "DDDDDDDDD        VVVV       DDDDDDDDD   ",
        "                  VV                    "
    ]
    aw = len(art[0])
    ah = len(art)
    pos = [t.w / 2, t.h / 2]
    vel = [1.12 / 2, 0.67 / 2]

    t.style(Color.hex(0x0000FF))
    t.style(Color.hex(0x000000).bg())
    t.style(Style("bold"))
    t.flush()

    def changecol():
        colors = (Color.hex(0x0000FF), Color.hex(0xFFFF00),
                  Color.hex(0x7700FF), Color.hex(0xFF0077),
                  Color.hex(0xFF7700))
        t.style(random.choice(colors))

    def update():
        t.clear_box(pos[0] - aw / 2, pos[1] - ah / 2, aw, ah)

        # integrate velocity
        pos[0] += vel[0]
        pos[1] += vel[1]

        # ugly bounce physics
        if pos[0] < aw / 2:
            pos[0] = aw / 2
            vel[0] = -vel[0]
            changecol()
        if pos[1] < ah / 2 + 1:
            pos[1] = ah / 2 + 1
            vel[1] = -vel[1]
            changecol()
        if pos[0] > t.w - 1 - aw / 2:
            pos[0] = t.w - 1 - aw / 2
            vel[0] = -vel[0]
            changecol()
        if pos[1] > t.h - 1 - ah / 2:
            pos[1] = t.h - 1 - ah / 2
            vel[1] = -vel[1]
            changecol()

        # update console
        draw_art(t, art, pos[0], pos[1])
        t.flush()

    def on_input(c):
        if c == "q":
            app.stop()

    app = TerminalApp(t, 60, update=update, on_input=on_input)
    app.start()
Esempio n. 2
0
from pytermfx import Terminal, Color, Style
from pytermfx.keys import MouseEvent
from time import clock

BASE_SIZE = 4
MAX_SIZE = BASE_SIZE * 3
old_x = 0
old_y = 0

t = Terminal()
t.set_cbreak(True)
t.mouse_enable("move")
t.cursor_set_visible(False)
t.clear().flush()

try:
	while True:
		t.style(Style.none)
		t.cursor_to(0,0)
		t.writeln("Hover over terminal")
		t.writeln("Press Q to quit")
		t.flush()

		c = t.getch()
		if isinstance(c, MouseEvent):
			if c.down:
				size = BASE_SIZE * 3
			elif c.left or c.right:
				size = BASE_SIZE * 2
			else:
				size = BASE_SIZE