mobject_update_utils

用于mobject连续动画的实用函数。

函数

always(method, *args, **kwargs)[源代码]
参数:

method (可调用对象)

返回类型:

Mobject

always_redraw(func)[源代码]

每帧重新绘制由函数构建的mobject。

此函数返回一个带有附加更新器的mobject,该更新器根据指定函数持续重新生成mobject。

参数:

func (可调用对象[[], Mobject]) – 一个没有(必需)输入参数并返回mobject的函数。

返回类型:

Mobject

示例

示例:TangentAnimation

from manim import *

class TangentAnimation(Scene):
    def construct(self):
        ax = Axes()
        sine = ax.plot(np.sin, color=RED)
        alpha = ValueTracker(0)
        point = always_redraw(
            lambda: Dot(
                sine.point_from_proportion(alpha.get_value()),
                color=BLUE
            )
        )
        tangent = always_redraw(
            lambda: TangentLine(
                sine,
                alpha=alpha.get_value(),
                color=YELLOW,
                length=4
            )
        )
        self.add(ax, sine, point, tangent)
        self.play(alpha.animate.set_value(1), rate_func=linear, run_time=2)
class TangentAnimation(Scene):
    def construct(self):
        ax = Axes()
        sine = ax.plot(np.sin, color=RED)
        alpha = ValueTracker(0)
        point = always_redraw(
            lambda: Dot(
                sine.point_from_proportion(alpha.get_value()),
                color=BLUE
            )
        )
        tangent = always_redraw(
            lambda: TangentLine(
                sine,
                alpha=alpha.get_value(),
                color=YELLOW,
                length=4
            )
        )
        self.add(ax, sine, point, tangent)
        self.play(alpha.animate.set_value(1), rate_func=linear, run_time=2)

always_rotate(mobject, rate=0.3490658503988659, **kwargs)[源代码]

一个以特定速率连续旋转的mobject。

参数:
  • mobject (Mobject) – 要旋转的mobject。

  • rate (浮点数) – mobject在一秒内旋转的角度。

  • kwargs – 传递给 Mobject.rotate() 的更多参数。

返回类型:

Mobject

示例

示例:SpinningTriangle

from manim import *

class SpinningTriangle(Scene):
    def construct(self):
        tri = Triangle().set_fill(opacity=1).set_z_index(2)
        sq = Square().to_edge(LEFT)

        # will keep spinning while there is an animation going on
        always_rotate(tri, rate=2*PI, about_point=ORIGIN)

        self.add(tri, sq)
        self.play(sq.animate.to_edge(RIGHT), rate_func=linear, run_time=1)
class SpinningTriangle(Scene):
    def construct(self):
        tri = Triangle().set_fill(opacity=1).set_z_index(2)
        sq = Square().to_edge(LEFT)

        # will keep spinning while there is an animation going on
        always_rotate(tri, rate=2*PI, about_point=ORIGIN)

        self.add(tri, sq)
        self.play(sq.animate.to_edge(RIGHT), rate_func=linear, run_time=1)

always_shift(mobject, direction=array([1., 0., 0.]), rate=0.1)[源代码]

一个以特定速率沿某个方向连续移动的mobject。

参数:
  • mobject (Mobject) – 要移动的mobject。

  • direction (ndarray[float64]) – 移动方向。该向量是归一化的,指定的幅度不相关。

  • rate (浮点数) – mobject在一秒内沿指定方向移动的Manim单位长度。

返回类型:

Mobject

示例

示例:ShiftingSquare

from manim import *

class ShiftingSquare(Scene):
    def construct(self):
        sq = Square().set_fill(opacity=1)
        tri = Triangle()
        VGroup(sq, tri).arrange(LEFT)

        # construct a square which is continuously
        # shifted to the right
        always_shift(sq, RIGHT, rate=5)

        self.add(sq)
        self.play(tri.animate.set_fill(opacity=1))
class ShiftingSquare(Scene):
    def construct(self):
        sq = Square().set_fill(opacity=1)
        tri = Triangle()
        VGroup(sq, tri).arrange(LEFT)

        # construct a square which is continuously
        # shifted to the right
        always_shift(sq, RIGHT, rate=5)

        self.add(sq)
        self.play(tri.animate.set_fill(opacity=1))

assert_is_mobject_method(method)[源代码]
参数:

method (可调用对象)

返回类型:

cycle_animation(animation, **kwargs)[源代码]
参数:

animation (动画)

返回类型:

Mobject

f_always(method, *arg_generators, **kwargs)[源代码]

always 函数的更函数式版本,它不接受参数,而是接受输出相关参数的函数。

参数:

method (可调用对象[[Mobject], None])

返回类型:

Mobject

turn_animation_into_updater(animation, cycle=False, delay=0, **kwargs)[源代码]

为动画的mobject添加一个更新器,该更新器应用动画的插值和更新函数

如果 `cycle` 为 True,则此动画会循环重复。否则,更新器将在完成后被移除。

delay 参数是动画开始前的延迟(秒)。

示例

示例:WelcomeToManim

from manim import *

class WelcomeToManim(Scene):
    def construct(self):
        words = Text("Welcome to")
        banner = ManimBanner().scale(0.5)
        VGroup(words, banner).arrange(DOWN)

        turn_animation_into_updater(Write(words, run_time=0.9))
        self.add(words)
        self.wait(0.5)
        self.play(banner.expand(), run_time=0.5)
class WelcomeToManim(Scene):
    def construct(self):
        words = Text("Welcome to")
        banner = ManimBanner().scale(0.5)
        VGroup(words, banner).arrange(DOWN)

        turn_animation_into_updater(Write(words, run_time=0.9))
        self.add(words)
        self.wait(0.5)
        self.play(banner.expand(), run_time=0.5)

参数:
  • animation (动画)

  • cycle (布尔值)

  • delay (浮点数)

返回类型:

Mobject