Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix unintended `kwargs` propagation in `LaggedStartMap` (#4613)

Irvanal Haq6f825e851341
diff --git a/manim/animation/composition.py b/manim/animation/composition.py
index 1da15e914..82488425f 100644
--- a/manim/animation/composition.py
+++ b/manim/animation/composition.py
@@ -353,7 +353,7 @@ class LaggedStartMap(LaggedStart):
Parameters
----------
- AnimationClass
+ animation_class
:class:`~.Animation` to apply to mobject.
mobject
:class:`~.Mobject` whose submobjects the animation, and optionally the function,
@@ -362,6 +362,17 @@ class LaggedStartMap(LaggedStart):
Function which will be applied to :class:`~.Mobject`.
run_time
The duration of the animation in seconds.
+ lag_ratio
+ Defines the delay after which the animation is applied to submobjects. A lag_ratio of
+ ``n.nn`` means the next animation will play when ``nnn%`` of the current animation has played.
+ Defaults to 0.05, meaning that the next animation will begin when 5% of the current
+ animation has played.
+
+ This does not influence the total runtime of the animation. Instead the runtime
+ of individual animations is adjusted so that the complete animation has the defined
+ run time.
+ kwargs
+ Further keyword arguments that are passed to `animation_class`.
Examples
--------
@@ -392,6 +403,7 @@ class LaggedStartMap(LaggedStart):
mobject: Mobject,
arg_creator: Callable[[Mobject], Iterable[Any]] | None = None,
run_time: float = 2,
+ lag_ratio: float = DEFAULT_LAGGED_START_LAG_RATIO,
**kwargs: Any,
):
if arg_creator is None:
@@ -406,4 +418,4 @@ class LaggedStartMap(LaggedStart):
if "lag_ratio" in anim_kwargs:
anim_kwargs.pop("lag_ratio")
animations = [animation_class(*args, **anim_kwargs) for args in args_list]
- super().__init__(*animations, run_time=run_time, **kwargs)
+ super().__init__(*animations, run_time=run_time, lag_ratio=lag_ratio)
diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py
index 8c5f044b2..3c7a3dcc3 100644
--- a/tests/module/animation/test_composition.py
+++ b/tests/module/animation/test_composition.py
@@ -5,14 +5,16 @@ from unittest.mock import MagicMock
import pytest
from manim.animation.animation import Animation, Wait
-from manim.animation.composition import AnimationGroup, Succession
+from manim.animation.composition import AnimationGroup, LaggedStartMap, Succession
from manim.animation.creation import Create, Write
from manim.animation.fading import FadeIn, FadeOut
from manim.constants import DOWN, UP
from manim.mobject.geometry.arc import Circle
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.polygram import RegularPolygon, Square
+from manim.mobject.types.vectorized_mobject import VGroup
from manim.scene.scene import Scene
+from manim.utils.rate_functions import linear, there_and_back
def test_succession_timing():
@@ -189,6 +191,23 @@ def test_animationgroup_calls_finish():
assert circ_animation.finished
+def test_laggedstartmap_only_passes_kwargs_to_subanimations():
+ mobject = VGroup(Square(), Circle())
+ animation = LaggedStartMap(
+ FadeIn,
+ mobject,
+ rate_func=there_and_back,
+ lag_ratio=0.3,
+ )
+
+ assert animation.rate_func is linear
+ assert animation.lag_ratio == 0.3
+ assert all(
+ subanimation.rate_func is there_and_back
+ for subanimation in animation.animations
+ )
+
+
def test_empty_animation_group_fails():
with pytest.raises(ValueError, match="Please add at least one subanimation."):
AnimationGroup().begin()