变换

完全限定名: manim.animation.transform.Transform

class Transform(mobject=None, *args, use_override=True, **kwargs)[源代码]

基类: Animation

一个 Transform 动画将一个 Mobject 变换成目标 Mobject。

参数:
  • mobject (Mobject | None) – 要被变换的 Mobject。它将被修改以成为 target_mobject

  • target_mobject (Mobject | None) – 变换的目标。

  • path_func (Callable | None) – 一个函数,定义了 mobject 的点移动的路径,直到它们与 target_mobject 的点匹配,参见 utils.paths

  • path_arc (float) – 如果使用圆形路径弧,`mobject` 的点将遵循的弧度角(以弧度为单位)以达到目标点,参见 `path_arc_centers`。另请参见 manim.utils.paths.path_along_arc()

  • path_arc_axis (np.ndarray) – 如果使用圆形路径弧,则旋转所沿的轴,参见 `path_arc_centers`。

  • path_arc_centers (np.ndarray) –

    变换过程中 mobject 的点沿其移动的圆形弧的中心。

    如果此项已设置且 path_func 未设置,则将使用 path_arc 参数生成一个 path_along_circles 路径并存储在 path_func 中。如果 path_func 已设置,则此项和其他 path_arc 字段将作为属性设置,但不会从中生成 path_func

  • replace_mobject_with_target_in_scene (bool) –

    控制当变换完成后哪个 mobject 被替换。

    如果设置为 True,mobject 将从场景中移除,并由 target_mobject 替换。否则,target_mobject 不会被添加,mobject 只会获取其形状。

示例

示例: TransformPathArc

from manim import *

class TransformPathArc(Scene):
    def construct(self):
        def make_arc_path(start, end, arc_angle):
            points = []
            p_fn = path_along_arc(arc_angle)
            # alpha animates between 0.0 and 1.0, where 0.0
            # is the beginning of the animation and 1.0 is the end.
            for alpha in range(0, 11):
                points.append(p_fn(start, end, alpha / 10.0))
            path = VMobject(stroke_color=YELLOW)
            path.set_points_smoothly(points)
            return path

        left = Circle(stroke_color=BLUE_E, fill_opacity=1.0, radius=0.5).move_to(LEFT * 2)
        colors = [TEAL_A, TEAL_B, TEAL_C, TEAL_D, TEAL_E, GREEN_A]
        # Positive angles move counter-clockwise, negative angles move clockwise.
        examples = [-90, 0, 30, 90, 180, 270]
        anims = []
        for idx, angle in enumerate(examples):
            left_c = left.copy().shift((3 - idx) * UP)
            left_c.fill_color = colors[idx]
            right_c = left_c.copy().shift(4 * RIGHT)
            path_arc = make_arc_path(left_c.get_center(), right_c.get_center(),
                                     arc_angle=angle * DEGREES)
            desc = Text('%d°' % examples[idx]).next_to(left_c, LEFT)
            # Make the circles in front of the text in front of the arcs.
            self.add(
                path_arc.set_z_index(1),
                desc.set_z_index(2),
                left_c.set_z_index(3),
            )
            anims.append(Transform(left_c, right_c, path_arc=angle * DEGREES))

        self.play(*anims, run_time=2)
        self.wait()
class TransformPathArc(Scene):
    def construct(self):
        def make_arc_path(start, end, arc_angle):
            points = []
            p_fn = path_along_arc(arc_angle)
            # alpha animates between 0.0 and 1.0, where 0.0
            # is the beginning of the animation and 1.0 is the end.
            for alpha in range(0, 11):
                points.append(p_fn(start, end, alpha / 10.0))
            path = VMobject(stroke_color=YELLOW)
            path.set_points_smoothly(points)
            return path

        left = Circle(stroke_color=BLUE_E, fill_opacity=1.0, radius=0.5).move_to(LEFT * 2)
        colors = [TEAL_A, TEAL_B, TEAL_C, TEAL_D, TEAL_E, GREEN_A]
        # Positive angles move counter-clockwise, negative angles move clockwise.
        examples = [-90, 0, 30, 90, 180, 270]
        anims = []
        for idx, angle in enumerate(examples):
            left_c = left.copy().shift((3 - idx) * UP)
            left_c.fill_color = colors[idx]
            right_c = left_c.copy().shift(4 * RIGHT)
            path_arc = make_arc_path(left_c.get_center(), right_c.get_center(),
                                     arc_angle=angle * DEGREES)
            desc = Text('%d°' % examples[idx]).next_to(left_c, LEFT)
            # Make the circles in front of the text in front of the arcs.
            self.add(
                path_arc.set_z_index(1),
                desc.set_z_index(2),
                left_c.set_z_index(3),
            )
            anims.append(Transform(left_c, right_c, path_arc=angle * DEGREES))

        self.play(*anims, run_time=2)
        self.wait()

方法

开始

开始动画。

从场景中清理

在动画完成后清理 Scene

创建目标

get_all_families_zipped

get_all_mobjects

获取动画中涉及的所有 mobject。

interpolate_submobject

属性

路径弧

路径函数

run_time

_original__init__(mobject, target_mobject=None, path_func=None, path_arc=0, path_arc_axis=array([0., 0., 1.]), path_arc_centers=None, replace_mobject_with_target_in_scene=False, **kwargs)

初始化自身。有关准确签名,请参阅 help(type(self))。

参数:
  • mobject (Mobject | None)

  • target_mobject (Mobject | None)

  • path_func (Callable | None)

  • path_arc (浮点数)

  • path_arc_axis (ndarray)

  • path_arc_centers (ndarray)

  • replace_mobject_with_target_in_scene (bool)

返回类型:

begin()[源代码]

开始动画。

此方法在动画播放时立即调用。应尽可能多的初始化,特别是任何 mobject 复制,都应在此方法中进行。

返回类型:

clean_up_from_scene(scene)[源代码]

在动画完成后清理 Scene

这包括如果动画是一个移除器,则 remove() 动画的 Mobject

参数:

scene (场景) – 动画应从中清理的场景。

返回类型:

get_all_mobjects()[源代码]

获取动画中涉及的所有 mobject。

顺序必须与 interpolate_submobject 的参数顺序匹配

返回:

mobject 序列。

返回类型:

序列[Mobject]