manim/tests/test_composition.py
Anton Ballmaier 15261ea65b
Fading module enhancements (#1454)
* finish draft implementation
* use @wrapss to remove docs problems
* reduce complexity and add doc deprecation
* Docs deprecated_params
* add decoratos to __init__
* Add decorators to documentation
* Finish detailed docs
* Apply suggestions from code review
Co-authored-by: Naveen M K <naveen@syrusdark.website>

* change since/until/message param docs
* Mark get_callable_info and deprecation_text_component as private
* change how until is included in warning messages
* Add The to parameter descriptions
* make params docs more readable
* make redirections docs clearer
* update dependency list
* order dependencies
* update examples
* fix dependency problem
* fix duplicate problem
* change decorator version
* updated lock file
* enhance function / method separation
* fix typo and double underscores
* rename message_ and replacement_
* Change warning to custom admonition
* remove [] as default parameters
* Remove "" around type
* fix bug and move to inspect
* doc string => docstring
* rename to deprecate
* change module docstring
* change to deprecation.py
* remove tests again
* Rename decorators.py to deprecate.py
* Update poetry.lock
* Test if deprecated class outputs the correct warning when used
* Rename deprecate to deprecation
* Shorten conditional for msg, since, util
* Specify decorator arguments in test
* Add tests for since and until as arguments
* Add test for msg argument for class
* Add test for replacement argument for class
* Remove unneeded docstring in deprecated class
* Add test for deprecate method, no args
* Update docstring examples, move deprecated method outside class
* Add test for method in class, since and message args
* Add test for deprecating nested class
* Add test for deprecated method in nested class
* Test deprecation of nested function
* Test param deprecation, only params argument
* Test deprecation of single method param
* Rename single param test method name
* Fix deprecated_params docstring whitespace
* Test parameter redirection using tuple
* Update warning msgs in deprecated_params docstring
* Test parameter redirection using lambda function
* Test param redirection from many to one
* Test param redirection from one to many
* Update Top.foo to deprecate with message
* FadeIn & FadeOut overhaul and deprecations
* Adjust examples
* Add docs
* Add simple example
* handle empty docstrings
* Update poetry.lock
* Deprecate ShowCreation using decorator to test the docs
* Test docstrings
* add examples
* Update example_scenes/basic.py

Co-authored-by: Laith Bahodi <70682032+hydrobeam@users.noreply.github.com>
Co-authored-by: Naveen M K <naveen@syrusdark.website>
Co-authored-by: Ricky Chon <rickychon99@gmail.com>
Co-authored-by: Laith Bahodi <70682032+hydrobeam@users.noreply.github.com>
2021-05-15 16:23:47 +02:00

99 lines
3.9 KiB
Python

from manim.animation.animation import Animation, Wait
from manim.animation.composition import AnimationGroup, Succession
from manim.animation.fading import FadeIn, FadeOut
from manim.constants import DOWN, UP
from manim.mobject.geometry import Circle, Line, Square
def test_succession_timing():
"""Test timing of animations in a succession."""
line = Line()
animation_1s = FadeIn(line, shift=UP, run_time=1.0)
animation_4s = FadeOut(line, shift=DOWN, run_time=4.0)
succession = Succession(animation_1s, animation_4s)
assert succession.get_run_time() == 5.0
succession.begin()
assert succession.active_index == 0
# The first animation takes 20% of the total run time.
succession.interpolate(0.199)
assert succession.active_index == 0
succession.interpolate(0.2)
assert succession.active_index == 1
succession.interpolate(0.8)
assert succession.active_index == 1
# At 100% and more, no animation must be active anymore.
succession.interpolate(1.0)
assert succession.active_index == 2
assert succession.active_animation is None
succession.interpolate(1.2)
assert succession.active_index == 2
assert succession.active_animation is None
def test_succession_in_succession_timing():
"""Test timing of nested successions."""
line = Line()
animation_1s = FadeIn(line, shift=UP, run_time=1.0)
animation_4s = FadeOut(line, shift=DOWN, run_time=4.0)
nested_succession = Succession(animation_1s, animation_4s)
succession = Succession(
FadeIn(line, shift=UP, run_time=4.0),
nested_succession,
FadeIn(line, shift=UP, run_time=1.0),
)
assert nested_succession.get_run_time() == 5.0
assert succession.get_run_time() == 10.0
succession.begin()
succession.interpolate(0.1)
assert succession.active_index == 0
# The nested succession must not be active yet, and as a result hasn't set active_animation yet.
assert not hasattr(nested_succession, "active_animation")
succession.interpolate(0.39)
assert succession.active_index == 0
assert not hasattr(nested_succession, "active_animation")
# The nested succession starts at 40% of total run time
succession.interpolate(0.4)
assert succession.active_index == 1
assert nested_succession.active_index == 0
# The nested succession second animation starts at 50% of total run time.
succession.interpolate(0.49)
assert succession.active_index == 1
assert nested_succession.active_index == 0
succession.interpolate(0.5)
assert succession.active_index == 1
assert nested_succession.active_index == 1
# The last animation starts at 90% of total run time. The nested succession must be finished at that time.
succession.interpolate(0.89)
assert succession.active_index == 1
assert nested_succession.active_index == 1
succession.interpolate(0.9)
assert succession.active_index == 2
assert nested_succession.active_index == 2
assert nested_succession.active_animation is None
# After 100%, nothing must be playing anymore.
succession.interpolate(1.0)
assert succession.active_index == 3
assert succession.active_animation is None
assert nested_succession.active_index == 2
assert nested_succession.active_animation is None
def test_animationbuilder_in_group():
sqr = Square()
circ = Circle()
animation_group = AnimationGroup(sqr.animate.shift(DOWN).scale(2), FadeIn(circ))
assert all(isinstance(anim, Animation) for anim in animation_group.animations)
succession = Succession(sqr.animate.shift(DOWN).scale(2), FadeIn(circ))
assert all(isinstance(anim, Animation) for anim in succession.animations)
def test_animationgroup_with_wait():
sqr = Square()
sqr_anim = FadeIn(sqr)
wait = Wait()
animation_group = AnimationGroup(wait, sqr_anim, lag_ratio=1)
animation_group.begin()
timings = animation_group.anims_with_timings
assert timings == [(wait, 0.0, 1.0), (sqr_anim, 1.0, 2.0)]