Example #1
0
def test_plane():
    bounds = Box([(0, 3), (0, 3), (0, 3)])
    plane = Plane((1.5, 1.5, 1.5), (1, 1, 1), bounds)
    field = set(bounds.render())
    points = field - set(plane.render())

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

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

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

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

            ----
            ----
            #---
            ##--
        ''').strip(),
    )
Example #2
0
def test_sphere():
    # Draw connected spheres, which are small enough to just be 8 points in a
    # 2x2x2 cube.
    a = Sphere((0.5, 0.5, 0.5), 1)
    b = Sphere((-0.5, -0.5, -0.5), 1)
    points = set(a.render()) | set(b.render())

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

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

            -##
            ###
            ##-

            -##
            -##
            ---
        ''').strip(),
    )
Example #3
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(),
    )
Example #4
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(),
    )
Example #5
0
def test_plane_sphere_boolean():
    # Draw a sphere and slice off the top half.
    sphere = Sphere((0, 0, 0), 3)
    plane = Plane((0, 0, 0), (0, 0, 1), sphere.bounds())
    points = set(sphere.render()) - set(plane.render())

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

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

            -###-
            #####
            #####
            #####
            -###-
        ''').strip(),
    )
from volume import draw_layers, Sphere

a = Sphere((0, 0, 0), 10)
b = Sphere((5, 5, 5), 10)

points = set(a.render()) | set(b.render())

sep = '-' * 80
print(sep)
for layer in draw_layers(points):
    print(layer)
    print(sep)

print(len(points))