变换¶
完全限定名: 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
获取动画中涉及的所有 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))。