Bishalsarang / Recursion-Tree-Visualizer

A simple python package that helps to visualise any recursive function by adding a single line of code.
https://pypi.org/project/recursion-visualiser/
MIT License
111 stars 17 forks source link

fix minsave duration parameter #31

Closed Sachin796 closed 1 year ago

Sachin796 commented 1 year ago

The PR is to fix the animation frequency while generating the gif using recursion-tree-visualizer package. While using the code below

@classmethod
    def write_gif(cls, name="out.gif", delay=3):
        images = []

        # sort frames images in ascending order to number in image filename
        # image filename: frames/temp_1.png
        sorted_images = sorted(
            glob.glob("frames/*.png"),
            key=lambda fn: int(fn.split("_")[1].split(".")[0])
        )

        for filename in sorted_images:
            images.append(imageio.imread(filename))
        print("Writing gif...")
        imageio.mimsave(name, images, duration=delay)
        print(f"Saved gif {name} successfully")
        # Delete temporary directory
        shutil.rmtree("frames")

It does generate the gifs properly, however. changing the delay parameter in vs.make_animation("fibonacci.gif", delay=0.5) from 10 --> 1 , or any other value does not make any difference.

def main():
    # Call function
    print(fib(n=6))
    # Save recursion tree to a file
    vs.make_animation("fibonacci.gif", delay=0.5)

The gif is still generated, and each node are displayed in a constant speed which is very fast.

Apparently changing the duration parameter to fps changes the speed in which each node is generated in the gif.

Bishalsarang commented 1 year ago

Can you please attach the gifs before and after?

Sachin796 commented 1 year ago

Can you please attach the gifs before and after?

Sure.. you can find it in the thread below.

Sachin796 commented 1 year ago

Animation