A problem with rendering nested animations in Manim

Question:

Code

from manim import *
import numpy as np
import math as math
class  MaclaurinSine(MovingCameraScene):
    def construct(self):
        self.camera.frame.scale(0.5)
        coords = NumberPlane()
        L = []

        def next_graph (n,x):
            f = math.fsum([(((-1)**m)*(x**(2*m+1))/(math.factorial(2*m+1))) for m in range(n)])
            return f

        graph_basic = coords.get_graph(lambda x:next_graph(0,x),x_range=[-17,17])
        self.add(graph_basic)
        for i in range(1,20):
            graph1 = coords.get_graph(lambda x:next_graph(i,x),x_range=[-17,17])
            a = ReplacementTransform(Group(*self.mobjects),graph1,run_time = 0.2)
            L.append(a)

        self.play(Succession(*[x for x in L],lag_ratio=1),self.camera.frame.animate.scale(3))

        self.wait(3)

The problem

This code works as expected except that there is one little problem
after the scene is rendered the scene ends with an annoying frame
(apparently, this frame is the sum of the animations applied to some graph).

What I tried

I tried to use LaggedStart instead of Succession and tried to
use methods like interpolate but (as I am still learning)
I got errors that I couldn’t fix.

I don’t know where the problem is rather than how to fix it. so
how to get rid of this last frame (in a way that enables me to
continue adding animations after this animation with no gaps
between the animations)

note: I am still learning this beautiful library so there are some ideas still tricky for me.

Thanks in advance.

This is what the last frame looks like:
enter image description here

This is the scene:
enter image description here

Asked By: George Nabil

||

Answers:

After a while, I returned back to this question. And after getting better at coding I found this simple solution (there are little differences just for better naming conventions and code quality)

This is the solution:

from manim import *  # manimCE v1.16
import numpy as np
import math as math

class  MaclaurinSine(MovingCameraScene):
    def construct(self):
        self.camera.frame.scale(0.6)
        
        def nth_series (n,x):
            terms = [(((-1) ** m) * (x ** (2 * m + 1)) / (math.factorial(2 * m + 1))) for m in range(n)]
            return sum(terms)
        
        coords = NumberPlane()
        transformations = []
        
        previous_graph = coords.plot_parametric_curve(
            lambda t:np.array([t, nth_series(0, t)]), t_range=[-17,17]
            )
        for i in range(1,20):
            new_graph = coords.plot_parametric_curve(
                lambda t:np.array([t, nth_series(i, t)]), t_range=[-17,17]
                )
            # just replacing ReplacementTransform with Transform
            trans = Transform(previous_graph, new_graph, run_time=0.4, rate_func=rate_functions.smooth)
            transformations.append(trans)
            
        self.wait(0.4)
        self.play(Succession(*transformations,lag_ratio=1), self.camera.frame.animate.scale(3))
        self.wait(1.5)
Answered By: George Nabil
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.