Transform#

Qualified name: manim.animation.transform.Transform

class Transform(mobject=None, *args, use_override=True, **kwargs)[source]#

Bases: Animation

A Transform transforms a Mobject into a target Mobject.

Parameters:
  • mobject (Mobject | None) – The Mobject to be transformed. It will be mutated to become the target_mobject.

  • target_mobject (Mobject | None) – The target of the transformation.

  • path_func (Callable | None) – A function defining the path that the points of the mobject are being moved along until they match the points of the target_mobject, see utils.paths.

  • path_arc (float) – The arc angle (in radians) that the points of mobject will follow to reach the points of the target if using a circular path arc, see path_arc_centers. See also manim.utils.paths.path_along_arc().

  • path_arc_axis (np.ndarray) – The axis to rotate along if using a circular path arc, see path_arc_centers.

  • path_arc_centers (np.ndarray) –

    The center of the circular arcs along which the points of mobject are moved by the transformation.

    If this is set and path_func is not set, then a path_along_circles path will be generated using the path_arc parameters and stored in path_func. If path_func is set, this and the other path_arc fields are set as attributes, but a path_func is not generated from it.

  • replace_mobject_with_target_in_scene (bool) –

    Controls which mobject is replaced when the transformation is complete.

    If set to True, mobject will be removed from the scene and target_mobject will replace it. Otherwise, target_mobject is never added and mobject just takes its shape.

Examples

Example: 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()

Methods

begin

Begin the animation.

clean_up_from_scene

Clean up the Scene after finishing the animation.

create_target

get_all_families_zipped

get_all_mobjects

Get all mobjects involved in the animation.

interpolate_submobject

Attributes

path_arc

path_func

begin()[source]#

Begin the animation.

This method is called right as an animation is being played. As much initialization as possible, especially any mobject copying, should live in this method.

Return type:

None

clean_up_from_scene(scene)[source]#

Clean up the Scene after finishing the animation.

This includes to remove() the Animation’s Mobject if the animation is a remover.

Parameters:

scene (Scene) – The scene the animation should be cleaned up from.

Return type:

None

get_all_mobjects()[source]#

Get all mobjects involved in the animation.

Ordering must match the ordering of arguments to interpolate_submobject

Returns:

The sequence of mobjects.

Return type:

Sequence[Mobject]