Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Call `.finish()` for every animation in `AnimationGroup` on finish (#3951)

Laifsyn46dbf3d3edca
diff --git a/manim/animation/composition.py b/manim/animation/composition.py
index 1391dbfd1..128066ba8 100644
--- a/manim/animation/composition.py
+++ b/manim/animation/composition.py
@@ -98,7 +98,8 @@ class AnimationGroup(Animation):
anim._setup_scene(scene)
def finish(self) -> None:
- self.interpolate(1)
+ for anim in self.animations:
+ anim.finish()
self.anims_begun[:] = True
self.anims_finished[:] = True
if self.suspend_mobject_updating:
diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py
index 53d5767aa..8c5f044b2 100644
--- a/tests/module/animation/test_composition.py
+++ b/tests/module/animation/test_composition.py
@@ -171,6 +171,24 @@ def test_animationgroup_is_passing_remover_to_nested_animationgroups():
assert polygon_animation.remover
+def test_animationgroup_calls_finish():
+ class MyAnimation(Animation):
+ def __init__(self, mobject):
+ super().__init__(mobject)
+ self.finished = False
+
+ def finish(self):
+ self.finished = True
+
+ scene = Scene()
+ sqr_animation = MyAnimation(Square())
+ circ_animation = MyAnimation(Circle())
+ animation_group = AnimationGroup(sqr_animation, circ_animation)
+ scene.play(animation_group)
+ assert sqr_animation.finished
+ assert circ_animation.finished
+
+
def test_empty_animation_group_fails():
with pytest.raises(ValueError, match="Please add at least one subanimation."):
AnimationGroup().begin()