制作方法动画

任何可以更改的 mobject 属性都可以被动画化。事实上,任何改变 mobject 属性的方法都可以用作动画,通过使用 :meth:'.animate'。

class AnimateExample(Scene):
    def construct(self):
        square = Square().set_fill(RED, opacity=1.0)
        self.add(square)

        # animate the change of color
        self.play(square.animate.set_fill(WHITE))
        self.wait(1)

        # animate the change of position and the rotation at the same time
        self.play(square.animate.shift(UP).rotate(PI / 3))
        self.wait(1)

:meth:'.animate' 是所有 mObjects 的一个属性,它使出现的方法产生动画效果 然后。 例如,设置square.set_fill(WHITE)正方形的填充颜色,同时square.animate.set_fill(WHITE)为此作添加动画效果。

Last updated