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)
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-size', metavar='s', type=int, default=800, help='image size') parser.add_argument('-order', metavar='o', type=int, default=60, help='order of az graph') parser.add_argument('-filename', metavar='f', type=str, default='random_tiling.png', help='output filename') parser.add_argument('-prog', metavar='p', type=str, default='cairo', help='program to draw the tiling') args = parser.parse_args() az = aztec.AztecDiamond(0) for _ in range(args.order): az = az.delete().slide().create() render(args.prog, az, args.size, az.order + 1, args.filename)