转换¶
限定名称: manim.animation.transform.Transform
- class Transform(mobject=None, *args, use_override=True, **kwargs)[来源]¶
基础类:
Animation一个Transform将一个Mobject转换为目标Mobject。
- Parameters:
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()方法
开始动画。
在完成动画后清理
场景。create_targetget_all_families_zipped获取动画中涉及的所有mobjects。
interpolate_submobject属性
path_arcpath_func