mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 19:46:21 +08:00
Fixed Succession to work when animations share a mobject
This commit is contained in:
@ -2,8 +2,10 @@ import numpy as np
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.mobject.mobject import Group
|
||||
from manimlib.utils.bezier import integer_interpolate
|
||||
from manimlib.utils.bezier import interpolate
|
||||
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 squish_rate_func
|
||||
|
||||
@ -13,7 +15,7 @@ class AnimationGroup(Animation):
|
||||
# If None, this defaults to the sum of all
|
||||
# internal animations
|
||||
"run_time": None,
|
||||
"rate_functions": linear,
|
||||
"rate_func": linear,
|
||||
# If 0, all animations are played at once.
|
||||
# If 1, all are played successively.
|
||||
# If >0 and <1, they start at lagged times
|
||||
@ -23,7 +25,9 @@ class AnimationGroup(Animation):
|
||||
|
||||
def __init__(self, *animations, **kwargs):
|
||||
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)
|
||||
self.init_run_time()
|
||||
|
||||
@ -97,6 +101,30 @@ class Succession(AnimationGroup):
|
||||
"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):
|
||||
CONFIG = {
|
||||
|
Reference in New Issue
Block a user