Succession should be reconstructed
Description of bug / unexpected behavior
Succession should be reconstructed as a group of animations rather than a group of mobjects.
In fact, we should reconstruct a series of classes for AnimationGroup, otherwise, a lot of bugs will appear.
Bug1
class s1(Scene):
def construct(self):
square = Square()
cirlce = Circle()
anim = Succession(Write(square), FadeIn(cirlce), FadeOut(cirlce))
self.play(anim)
In this case, square and circle will add to the screen at the beginning, then play the corresponding animation.
Bug2
class s1(Scene):
def construct(self):
square = Square()
self.add(square)
print(square in self.mobjects) # True
self.play(Succession(square.animate.shift(UP), Rotate(square)))
print(square in self.mobjects) # False
In this case, after playing the animation Succession, square are considered not in self.mobjects.
Bug 3
class Test(Scene):
def construct(self):
r1 = Rectangle(width=2, height=2, color=BLUE, fill_color=BLUE, fill_opacity=1)
r2 = Square(side_length=0.5, color=RED, fill_color=RED, fill_opacity=1).move_to(r1.get_edge_center(RIGHT))
self.add(r1, r2)
self.play(
Succession(
ApplyMethod(r2.set_fill, YELLOW, run_time=2),
ApplyMethod(r1.set_fill, GREEN, run_time=0.4),
)
)
self.wait()
The mobjects are added to the scene in a particular order, so that the red square is painted over the blue rectangle.
However, Succession() alters that order, because when scanning the objects in the animation r2 is found before r1, so the group constructed is [r2, r1]. The visible result is that the blue rectangle is painted over the red square.
Of course, since Succession() is only a subclass of AnimationGroup, the true problem is in the latter. In particular here https://github.com/ManimCommunity/manim/blob/main/manim/animation/composition.py#L69
Seems that the same piece of code composition.py#L69 may be behind issue #3133