mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Fixed Succession to work when animations share a mobject
This commit is contained in:
parent
64eb670027
commit
eb7f1e21a3
1 changed files with 30 additions and 2 deletions
|
@ -2,8 +2,10 @@ import numpy as np
|
||||||
|
|
||||||
from manimlib.animation.animation import Animation
|
from manimlib.animation.animation import Animation
|
||||||
from manimlib.mobject.mobject import Group
|
from manimlib.mobject.mobject import Group
|
||||||
|
from manimlib.utils.bezier import integer_interpolate
|
||||||
from manimlib.utils.bezier import interpolate
|
from manimlib.utils.bezier import interpolate
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
|
from manimlib.utils.iterables import remove_list_redundancies
|
||||||
from manimlib.utils.rate_functions import linear
|
from manimlib.utils.rate_functions import linear
|
||||||
from manimlib.utils.rate_functions import squish_rate_func
|
from manimlib.utils.rate_functions import squish_rate_func
|
||||||
|
|
||||||
|
@ -13,7 +15,7 @@ class AnimationGroup(Animation):
|
||||||
# If None, this defaults to the sum of all
|
# If None, this defaults to the sum of all
|
||||||
# internal animations
|
# internal animations
|
||||||
"run_time": None,
|
"run_time": None,
|
||||||
"rate_functions": linear,
|
"rate_func": linear,
|
||||||
# If 0, all animations are played at once.
|
# If 0, all animations are played at once.
|
||||||
# If 1, all are played successively.
|
# If 1, all are played successively.
|
||||||
# If >0 and <1, they start at lagged times
|
# If >0 and <1, they start at lagged times
|
||||||
|
@ -23,7 +25,9 @@ class AnimationGroup(Animation):
|
||||||
|
|
||||||
def __init__(self, *animations, **kwargs):
|
def __init__(self, *animations, **kwargs):
|
||||||
self.animations = animations
|
self.animations = animations
|
||||||
self.group = Group(*[anim.mobject for anim in animations])
|
self.group = Group(*remove_list_redundancies(
|
||||||
|
[anim.mobject for anim in animations]
|
||||||
|
))
|
||||||
Animation.__init__(self, self.group, **kwargs)
|
Animation.__init__(self, self.group, **kwargs)
|
||||||
self.init_run_time()
|
self.init_run_time()
|
||||||
|
|
||||||
|
@ -97,6 +101,30 @@ class Succession(AnimationGroup):
|
||||||
"lag_ratio": 1,
|
"lag_ratio": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __init__(self, *animations, **kwargs):
|
||||||
|
self.active_animation = animations[0]
|
||||||
|
super().__init__(*animations, **kwargs)
|
||||||
|
|
||||||
|
def begin(self):
|
||||||
|
self.active_animation.begin()
|
||||||
|
|
||||||
|
def finish(self):
|
||||||
|
self.active_animation.finish()
|
||||||
|
|
||||||
|
def update_mobjects(self, dt):
|
||||||
|
self.active_animation.update_mobjects(dt)
|
||||||
|
|
||||||
|
def interpolate(self, alpha):
|
||||||
|
index, subalpha = integer_interpolate(
|
||||||
|
0, len(self.animations), alpha
|
||||||
|
)
|
||||||
|
animation = self.animations[index]
|
||||||
|
if animation is not self.active_animation:
|
||||||
|
self.active_animation.finish()
|
||||||
|
animation.begin()
|
||||||
|
self.active_animation = animation
|
||||||
|
animation.interpolate(subalpha)
|
||||||
|
|
||||||
|
|
||||||
class LaggedStart(AnimationGroup):
|
class LaggedStart(AnimationGroup):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue