X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/7b93cea1daf2889e9ee10ca9c22a1b5124404937..6d08d8c0a84c1ffa31f5eb16e33b340727f46175:/examples/menger.py diff --git a/examples/menger.py b/examples/menger.py index d8a74d4..dcba976 100755 --- a/examples/menger.py +++ b/examples/menger.py @@ -1,5 +1,18 @@ #!/usr/bin/env python3 +# Plot a Menger sponge. +# +# The construction of a Menger sponge can be described as follows: +# +# 1. Begin with a cube. +# 2. Divide every face of the cube into 9 squares, like a Rubik's Cube. This +# will sub-divide the cube into 27 smaller cubes. +# 3. Remove the smaller cube in the middle of each face, and remove the smaller +# cube in the very center of the larger cube, leaving 20 smaller cubes. This +# is a level-1 Menger sponge (resembling a Void Cube). +# 4. Repeat steps 2 and 3 for each of the remaining smaller cubes, and continue +# to iterate. + import argparse import matplotlib.pyplot as plt @@ -11,6 +24,7 @@ from mpl_toolkits.mplot3d import Axes3D from linpy import * + x, y, z = symbols('x y z') _x, _y, _z = x.asdummy(), y.asdummy(), z.asdummy() @@ -56,8 +70,8 @@ def menger(domain, count=1, cut=False): if __name__ == '__main__': parser = argparse.ArgumentParser( description='Compute a Menger sponge.') - parser.add_argument('-n', '--iterations', type=int, default=1, - help='number of iterations (default: 1)') + parser.add_argument('-n', '--iterations', type=int, default=2, + help='number of iterations (default: 2)') parser.add_argument('-c', '--cut', action='store_true', default=False, help='cut the sponge') args = parser.parse_args()