Пример #1
0
def test_parametric_torus():
    # Draw a torus using a parametric path.
    def circle(t):
        r = 1.9
        x = r * math.sin(t)
        y = r * math.cos(t)
        z = 0
        return (x, y, z)

    def radius_func(t):
        return 0.9

    torus = Path(
        circle,
        radius_func,
        tmin=0,
        tmax=(2 * math.pi),
    )

    points = torus.render()
    layers = draw_layers(points, on='#', off='-')

    assert_equal(
        '\n\n'.join(layers),
        dedent('''
            -###-
            ##-##
            #---#
            ##-##
            -###-
        ''').strip(),
    )
Пример #2
0
def test_parametric_changing_radius():
    # Draw a variable width line.
    start = Point3(0.5, 0, 0)
    end = Point3(19.5, 0, 0)

    def line(t):
        x = lerp(start.x, end.x, t)
        y = lerp(start.y, end.y, t)
        z = lerp(start.z, end.z, t)
        return (x, y, z)

    def radius_func(t):
        # Get larger until the middle, then get smaller again.
        if t < 0.5:
            return lerp(0, 3.5, t)
        else:
            return lerp(3.5, 0, t)

    path = Path(
        line,
        radius_func,
        tmin=0,
        tmax=1,
    )

    points = path.render()
    layers = draw_layers(points, on='#', off='-')

    assert_equal(
        '\n\n'.join(layers),
        dedent('''
            --------###--------
            -----#########-----
            --------###--------

            -----#########-----
            ###################
            -----#########-----

            --------###--------
            -----#########-----
            --------###--------
        ''').strip(),
    )