A community-maintained Python framework for creating mathematical animations.
Fix Bug `Uncreate()` with `rate_func` via introducing new parameter `reversed` to class `Animation` (#2597)
darkways5071e9418b40
diff --git a/manim/animation/animation.py b/manim/animation/animation.pyindex 2805e0402..385917e16 100644--- a/manim/animation/animation.py+++ b/manim/animation/animation.py@@ -49,6 +49,13 @@ class Animation:For example ``rate_func(0.5)`` is the proportion of the animation that is doneafter half of the animations run time.+++ reverse_rate_function+ Reverses the rate function of the animation. Setting ``reverse_rate_function``+ does not have any effect on ``remover`` or ``introducer``. These need to be+ set explicitly if an introducer-animation should be turned into a remover one+ and vice versa.nameThe name of the animation. This gets displayed while rendering the animation.Defaults to <class-name>(<Mobject-name>).@@ -123,6 +130,7 @@ class Animation:lag_ratio: float = DEFAULT_ANIMATION_LAG_RATIO,run_time: float = DEFAULT_ANIMATION_RUN_TIME,rate_func: Callable[[float], float] = smooth,+ reverse_rate_function: bool = False,name: str = None,remover: bool = False, # remove a mobject from the screen?suspend_mobject_updating: bool = True,@@ -134,6 +142,7 @@ class Animation:self._typecheck_input(mobject)self.run_time: float = run_timeself.rate_func: Callable[[float], float] = rate_func+ self.reverse_rate_function: bool = reverse_rate_functionself.name: str | None = nameself.remover: bool = removerself.introducer: bool = introducer@@ -361,7 +370,10 @@ class Animation:full_length = (num_submobjects - 1) * lag_ratio + 1value = alpha * full_lengthlower = index * lag_ratio- return self.rate_func(value - lower)+ if self.reverse_rate_function:+ return self.rate_func(1 - (value - lower))+ else:+ return self.rate_func(value - lower)# Getters and settersdef set_run_time(self, run_time: float) -> Animation:diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex 1b2eddda7..8abc26568 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -191,13 +191,13 @@ class Uncreate(Create):def __init__(self,mobject: VMobject | OpenGLVMobject,- rate_func: Callable[[float], float] = lambda t: smooth(1 - t),+ reverse_rate_function: bool = True,remover: bool = True,**kwargs,) -> None:super().__init__(mobject,- rate_func=rate_func,+ reverse_rate_function=reverse_rate_function,introducer=False,remover=remover,**kwargs,@@ -405,7 +405,7 @@ class Unwrite(Write):vmobject,run_time=run_time,lag_ratio=lag_ratio,- rate_func=lambda t: -rate_func(t) + 1,+ reverse_rate_function=True,reverse=reverse,**kwargs,)diff --git a/tests/test_graphical_units/control_data/creation/uncreate_rate_func.npz b/tests/test_graphical_units/control_data/creation/uncreate_rate_func.npznew file mode 100644index 000000000..3826c14faBinary files /dev/null and b/tests/test_graphical_units/control_data/creation/uncreate_rate_func.npz differdiff --git a/tests/test_graphical_units/test_creation.py b/tests/test_graphical_units/test_creation.pyindex c6ce35ba1..c6cfc3e50 100644--- a/tests/test_graphical_units/test_creation.py+++ b/tests/test_graphical_units/test_creation.py@@ -19,6 +19,13 @@ def test_uncreate(scene):scene.play(Uncreate(square))+@frames_comparison(last_frame=False)+def test_uncreate_rate_func(scene):+ square = Square()+ scene.add(square)+ scene.play(Uncreate(square), rate_func=linear)++@frames_comparison(last_frame=False)def test_DrawBorderThenFill(scene):square = Square(fill_opacity=1)