Update

UpdateFromFunc

class manimlib.animation.update.UpdateFromFunc(mobject, update_function, **kwargs)

时刻使用update_function来更新mobject

UpdateFromFuncExample
class UpdateFromFuncExample(Scene):
    def construct(self):
        square = Square().to_edge(UP)
        mobject = TextMobject("Text").scale(2).next_to(square, RIGHT)
        def update_func(mob):
            mob.next_to(square, RIGHT)

        self.add(square, mobject)
        self.wait()
        self.play(
            square.to_edge, DOWN,
            UpdateFromFunc(mobject, update_func)
        )
        self.wait()

UpdateFromAlphaFunc

class manimlib.animation.update.UpdateFromAlphaFunc(mobject, update_function, **kwargs)

传入的函数含有参数alpha,表示动画完成度(0~1之间)

UpdateFromAlphaFuncExample
class UpdateFromAlphaFuncExample(Scene):
    def construct(self):
        square = Square().to_edge(UP)
        mobject = TextMobject("Text").scale(2)
        mobject.next_to(square, RIGHT, buff=0.05)
        def update_func(mob, alpha):
            mob.next_to(square, RIGHT, buff=0.05 + alpha)

        self.add(square, mobject)
        self.wait()
        self.play(
            square.to_edge, DOWN,
            UpdateFromAlphaFunc(mobject, update_func)
        )
        self.wait()

MaintainPositionRelativeTo

class manimlib.animation.update.MaintainPositionRelativeTo(mobject, tracked_mobject, **kwargs)

维持mobject与tracked_mobject之间的相对位置关系

MaintainPositionRelativeToExample
class MaintainPositionRelativeToExample(Scene):
    def construct(self):
        square = Square().to_edge(UP)
        mobject = TextMobject("Text").scale(2)
        mobject.next_to(square, RIGHT)

        self.add(square, mobject)
        self.wait()
        self.play(
            square.to_edge, DOWN,
            MaintainPositionRelativeTo(mobject, square)
        )
        self.wait()