mobject_update_utils

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

函数

always(method, *args, **kwargs)[source]
Parameters:

方法 (可调用的)

Return type:

Mobject

always_redraw(func)[来源]

每一帧都重新绘制由函数构造的mobject。

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

Parameters:

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

Return type:

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)[source]

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

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

  • rate (float) – 物体在一秒钟内旋转的角度。

  • kwags – 传递给 Mobject.rotate() 的进一步参数。

Return type:

Mobject

示例

示例:旋转三角形

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)[source]

一个沿着某个方向以一定速率连续移动的物体。

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

  • direction (ndarray[float64]) – 移动的方向。向量会被归一化,指定的大小不相关。

  • rate (float) – 以Manim单位表示的长度,表示物体在指定方向上每秒移动的距离。

Return type:

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)[source]
Parameters:

方法 (可调用的)

Return type:

cycle_animation(animation, **kwargs)[source]
Parameters:

动画 (动画)

Return type:

Mobject

f_always(method, *arg_generators, **kwargs)[source]

always 的更多功能版本,其中不是直接接受参数,而是接受输出相关参数的函数。

Parameters:

方法 (可调用的[[Mobject], ])

Return type:

Mobject

turn_animation_into_updater(animation, cycle=False, **kwargs)[来源]

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

如果cycle为True,这将不断重复。否则,更新器将在完成后弹出。

示例

示例: 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)

Parameters:
  • 动画 (动画)

  • cycle (布尔值)

Return type:

Mobject