예제 #1
0
def make_animation(order, size, filename):
    """
    Render one frame for each step in the algorithm and then
    use ImageMagick to convert the images into a gif.
    """
    az = aztec.AztecDiamond(0)
    for i in range(order):
        az.delete()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i))

        az = az.slide()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i + 1))

        az.create()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i + 2))

    command = [
        CONVERTER, '-layers', 'Optimize', '-delay', '15',
        '_tmp%03d.png[0-{}]'.format(3 * order - 2), '-delay', '500',
        '_tmp{:03d}.png'.format(3 * order - 1), filename
    ]
    subprocess.check_call(command)

    # do the clean up
    for f in glob.glob('_tmp*.png'):
        os.remove(f)
def make_animation(order, size, filename):
    """
    Begin with the Aztec diamond of order zero, repeat the operations
    `delete`, `slide` and `create` until its order reaches `order`.
    Render one frame for each operation and call ImageMagick to
    convert the images to a gif file.

    Parameters
    ----------
    :order:  total steps to run the algorithm.
    :size:  size of the gif image.
    :filename:  the output .gif filename.
    """
    az = aztec.AztecDiamond(0)
    for i in trange(order):
        az.delete()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i))

        az = az.slide()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i + 1))

        az.create()
        render(az, size, order + 1, '_tmp{:03d}.png'.format(3 * i + 2))

    command = [
        CONVERTER, '-layers', 'Optimize', '-delay', '15',
        '_tmp%03d.png[0-{}]'.format(3 * order - 2), '-delay', '500',
        '_tmp{:03d}.png'.format(3 * order - 1), filename
    ]
    subprocess.check_call(command)

    # do the clean up
    for f in glob.glob('_tmp*.png'):
        os.remove(f)