manim/tests/test_graphical_units/test_creation.py
darkways 5071e9418b
Fix Bug Uncreate() with rate_func via introducing new parameter reversed to class Animation (#2597)
* `Uncreate()` works with `rate_func` ,fix #2469

Place the reverse of `rate_func` to become part of the process in `Uncreate()`.

The original `uncreate()` is implemented by setting a specific value to `rate_func`.

Now, if you want to set parameter`rate_func` when using `Uncreate()`, you can set the parameter `reverse_rate_func` to `Uncreate()`.

Examples

```python
.. manim:: ShowUncreate

        class ShowUncreate(Scene):
            def construct(self):
                self.play(Uncreate(Square(), reverse_rate_func=linear))
```

But problems remains when you try to pass parameter `rate_func` to `Scene.play()`

* fix issue #2469

* Add parameter reversed to class Animation

Fix an error in the last [commit](47b5196e3f). The "remover" decided whether it would reverse. Now it correctly passes the power of decision to "reversed".
Add a bool parameter `reversed` to class `Animation`. It decides whether the animation need to be played backwards. Default to be False.

* Add unit tests for usages of `Uncreate()`

* Add control data for the new unit test

* change the implementation of `Unwrite` to the same logic as `Uncreate`

* Rename parameter `reversed`, add descriptions, style #2597

Rename `reversed` to the more explicit `reverse_rate_function`, in class Animation.
Explicitly mention in documentation that setting `reverse_rate_function` doesn't have any effect on `remover` and `introducer`.

* improve documentation of parameter `reverse_rate_function`, doc #2597

improve documentation of parameter `reverse_rate_function` in class `Animation`

Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>

* doc: remove unnecessary comments in creation.py

The comment was added because the name of the parameter `reversed` was similar to reverse, which is a also parameter, but defined in Write().
Now the parameter has a more explicit name `reverse_rate_function`. Developers can get the main idea from its name. So we don't need the comment to tell.

Co-authored-by: Sefik-Palazoglu <sefik.palazoglu.s@gmail.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
2022-04-09 09:49:16 +00:00

96 lines
2.3 KiB
Python

from __future__ import annotations
from manim import *
from manim.utils.testing.frames_comparison import frames_comparison
__module_test__ = "creation"
@frames_comparison(last_frame=False)
def test_create(scene):
square = Square()
scene.play(Create(square))
@frames_comparison(last_frame=False)
def test_uncreate(scene):
square = Square()
scene.add(square)
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)
scene.play(DrawBorderThenFill(square))
# NOTE : Here should be the Write Test. But for some reasons it appears that this function is untestable (see issue #157)
@frames_comparison(last_frame=False)
def test_FadeOut(scene):
square = Square()
scene.add(square)
scene.play(FadeOut(square))
@frames_comparison(last_frame=False)
def test_FadeIn(scene):
square = Square()
scene.play(FadeIn(square))
@frames_comparison(last_frame=False)
def test_GrowFromPoint(scene):
square = Square()
scene.play(GrowFromPoint(square, np.array((1, 1, 0))))
@frames_comparison(last_frame=False)
def test_GrowFromCenter(scene):
square = Square()
scene.play(GrowFromCenter(square))
@frames_comparison(last_frame=False)
def test_GrowFromEdge(scene):
square = Square()
scene.play(GrowFromEdge(square, DOWN))
@frames_comparison(last_frame=False)
def test_SpinInFromNothing(scene):
square = Square()
scene.play(SpinInFromNothing(square))
@frames_comparison(last_frame=False)
def test_ShrinkToCenter(scene):
square = Square()
scene.play(ShrinkToCenter(square))
@frames_comparison(last_frame=False)
def test_bring_to_back_introducer(scene):
a = Square(color=RED, fill_opacity=1)
b = Square(color=BLUE, fill_opacity=1).shift(RIGHT)
scene.add(a)
scene.bring_to_back(b)
scene.play(FadeIn(b))
scene.wait()
@frames_comparison(last_frame=False)
def test_z_index_introducer(scene):
a = Circle().set_fill(color=RED, opacity=1.0)
scene.add(a)
b = Circle(arc_center=(0.5, 0.5, 0.0), color=GREEN, fill_opacity=1)
b.set_z_index(-1)
scene.play(Create(b))
scene.wait()