Example #1
0
def main():
    """Drawing API example for plotting a Bezier-curve
    """
    with Screen() as scr:
        scr.high.draw.bezier((0, 0), (0, 40), (100, 40), (100, 10))
        #scr.high.draw.bezier(
        #(100,10), (100, 0), (150, 0), (150, 40)
        #)
        scr.high.draw.bezier((100, 10), (125, 0), (125, 50), (150, 40))
        pause()
Example #2
0
def main(text, position, size, color, clear, font):
    """Terminedia example for rendering large text characters
    """
    position = literal_eval(f"({position})")
    color = literal_eval(f"({color})") if color.count(",") >= 2 else getattr(
        terminedia.values, color)
    with Screen(clear_screen=clear) as sc:
        sc.context.color = color
        sc.context.font = font
        sc.text[size].at(position, text)
        pause()
Example #3
0
def main(phrases=(), clear=True):
    if not phrases:
        phrases = ["Hello World! 1234"]

    with TM.Screen(clear_screen=clear) as sc:
        for line, (phrase, effect) in enumerate(zip(cycle(phrases),
                                                    TM.Effects)):
            sc.context.effects = TM.Effects.none

            sc.print_at((0, line), f"{effect.name}: ")
            sc.context.effects = effect
            sc.print(phrase)
        TM.pause()
Example #4
0
def main(image_paths):
    """Displays an image, given in a path, on the terminal.
    """
    # TODO add more options to control the output,
    # including disabling auto-scaling.
    if not image_paths:
        image_paths = (default_image, )
    with Screen() as scr:
        for img_path in image_paths:
            img = shape(img_path)
            with scr.commands:
                scr.draw.blit((0, 0), img)
        pause()
Example #5
0
def main(phrases=(), effects=(), clear=True):
    if not phrases:
        phrases = ["Hello World! 1234"]

    if not effects:
        effects = TM.Effects
    else:
        effects = [getattr(TM.Effects, effect, TM.Effects.none) for effect in effects]


    with TM.Screen(clear_screen=clear) as sc:
        for line, (phrase, effect) in enumerate(zip(cycle(phrases), effects)):
            sc.context.effects = TM.Effects.none

            sc.text[1][0, line] = f"{(effect.name + ':') if len(effects) > 1 else ''}[effect: {effect.name}]{phrase}"
            # sc.context.effects = effect
            # sc.text[1].print(phrase)
        TM.pause()
Example #6
0
def main(text, position, size, color, clear, font):
    """Terminedia example for rendering large text characters
    """
    position = literal_eval(f"({position})")
    if color == "default":
        color = DEFAULT_FG
    else:
        color = Color(
            literal_eval(f"({color})") if color.count(",") >= 2 else color)
    if size.isdigit():
        size = int(size)
    elif size == "square":
        size = (8, 4)
    with Screen(clear_screen=clear) as sc:
        sc.context.color = color
        sc.context.font = font
        sc.text[size].at(position, text)
        pause()
Example #7
0
    def rendering_test(*args, set_render_method, DISPLAY, DELAY, **kwargs):
        set_render_method()
        stdout = io.StringIO()

        fn = func(*args, **kwargs)
        with mock.patch("sys.stdout", stdout):
            next(fn)

        while True:

            if DISPLAY:
                print(stdout.getvalue())
                TM.pause(DELAY)
            try:
                fn.send(stdout.getvalue())
                stdout.seek(0)
                stdout.truncate()
            except StopIteration:
                break
Example #8
0
def main(image_paths, output=""):
    """Displays an image, given in a path, on the terminal.
    """
    # TODO add more options to control the output,
    # including disabling auto-scaling.
    if not image_paths:
        image_paths = (default_image, )
    scr = Screen()
    if output:
        output_file = open(output, "wt", encoding="utf-8")
    else:
        scr.clear()
    for img_path in image_paths:
        img = shape(img_path, screen=scr)
        if output:
            img.render(output=output_file)
            output_file.write("\n")
        else:
            with scr.commands:
                scr.draw.blit((0, 0), img)
            pause()
Example #9
0
def main(image_paths, size=None, output="", backend="", resolution=""):
    """Displays an image, given in a path, on the terminal.
    """
    # TODO add more options to control the output,
    # including disabling auto-scaling.
    if not image_paths:
        image_paths = (default_image, )
    context = scr = Screen(backend=backend)
    if not size:
        size = size_in_pixels(scr.size, resolution=resolution)
    else:
        size = V2(int(comp) for comp in size.lower().split("x"))
    if output:
        output_file = open(output, "wt", encoding="utf-8")
        context = DummyCtx()
    with context:
        for img_path in image_paths:
            if not resolution:
                img = shape(img_path, size=size)
            elif resolution == "square":
                img = shape(img_path,
                            size=size,
                            promote=True,
                            resolution=resolution)
            else:
                # For finer than half-block, threshold image prior to rendering
                preliminar_img = shape(img_path, size=size, promote=True)
                img = shape(size_in_blocks(size, resolution))
                preliminar_img.context.transformers.append(
                    ThresholdTransformer(invert=False))
                getattr(img, resolution).draw.blit((0, 0), preliminar_img)

            if output:
                img.render(output=output_file, backend=backend)
                output_file.write("\n")
            else:
                scr.clear()
                with scr.commands:
                    scr.draw.blit((0, 0), img)
                pause()
Example #10
0
def test_ellipses(scr, sleep=0.2):
    import random
    # scr.draw.ellipse((0, 0), (40, 20))
    scr.context.color = 0.5, 0, 1
    scr.high.draw.ellipse((90, 15), (200, 50), fill=True)

    scr.context.color = 1, 1, 1
    scr.high.draw.ellipse((90, 15), (200, 50), fill=False)
    scr.high.draw.ellipse((5, 3), (85, 60), fill=False)
    pause()

    for i in range(30):
        with scr.commands:
            for x in range(0, scr.high.get_size()[0] - 50, 10):
                for y in range(0, scr.high.get_size()[1] - 30, 10):
                    scr.context.color = random.uniform(0, 1), random.uniform(
                        0, 1), random.uniform(0, 1)
                    scr.high.draw.ellipse((x, y),
                                          (x + random.randrange(10, 40),
                                           y + random.randrange(5, 20)))
                    inkey()
        time.sleep(sleep)
Example #11
0
def test_valueshape_concat(direction, quantity, exp_width, exp_height, exp_data, DISPLAY, DELAY):
    a = IMG.ValueShape.new((3, 3), color=(0,0,0))
    b = IMG.ValueShape.new((3, 3), color=(0,0,0))

    a[0, 0] = (255,0,0)
    b[2, 2] = (128, 128, 255)
    c = a.concat(*((b,) * quantity), direction=direction)

    compare_data = [v[0] for v in c.data]

    if DISPLAY:
        with TM.Screen(clear_screen=True) as sc:
            sc.draw.blit((0,0), c)
            sc.context.color = (128, 128, 255)
            sc.print_at((0, 11), f"quantity={quantity}, width={c.width}, heigth={c.height}")
            sc.print_at((0, 10), f"{compare_data!r}")
            TM.pause(DELAY)


    assert c.width == exp_width
    assert c.height == exp_height
    assert  compare_data == exp_data
Example #12
0
    angle_inc = 2 * math.pi / rate

    for r in range(10, 55, 3):
        for i in range(rate):
            angle = angle_inc * i
            x, y = polar_coordinate(center_x, center_y, r + randrange(-2, 2), angle)

            context.color = choice([
                (1, 0, 1),
                (1, 1, 0),
                (0, 1, 1),
            ])
            line((x, y), (x, y))


with Screen() as scr:
    term = os.get_terminal_size()
    max_x = term.columns * 2
    max_y = term.lines * 2

    center_x, center_y = max_x // 2, max_y // 2
    shape(scr, center_x, center_y)

    center_x, center_y = 3 * max_x // 4, max_y // 2
    shape(scr, center_x, center_y)

    center_x, center_y = max_x // 4, max_y // 2
    shape(scr, center_x, center_y)

    pause()
Example #13
0
def main(sleep=0.2):
    """Example and benchmark tests for the drawing API using ellipses
    """
    with realtime_keyb(), Screen() as scr:
        test_ellipses(scr, sleep)
        pause()
Example #14
0
def main(func=None, domain=(-2, 2)):
    if func is None:
        func = "-2 * x**3 - 3 * x**2 + x - 1"
    with Screen() as sc:
        plot(sc, func, domain)
        pause()