Transformations

Transform

class manimlib.animation.transform.Transform(mobject, target_mobject, **kwargs)

Type: Animation

Parameters
  • mobject (Mobject) -- TODO

  • target_mobject (target_mobject) -- TODO

CONFIG parameters

"path_arc": 0,
"path_arc_axis": OUT,
"path_func": None,
"submobject_mode": "all_at_once",
"replace_mobject_with_target_in_scene": False,
class TransformExample(Scene):
    def construct(self):
        mobject = RegularPolygon(3).scale(2)

        self.add(mobject)

        for n in range(4,9):
            self.play(
                Transform(
                    mobject,
                    RegularPolygon(n).scale(2)
                )
            )

        self.wait(0.3)

Replacement Transform

class manimlib.animation.transform.ReplacementTransform(mobject, target_mobject, **kwargs)

Type: Transform

Same parameters

CONFIG parameters

"replace_mobject_with_target_in_scene": True,
class ReplacementTransformExample(Scene):
    def construct(self):
        polygons = [*[RegularPolygon(n).scale(2) for n in range(3,9)]]

        self.add(polygons[0])

        for i in range(len(polygons)-1):
            self.play(
                ReplacementTransform(
                    polygons[i],
                    polygons[i+1]
                )
            )

        self.wait(0.3)

Transform From Copy

class manimlib.animation.transform.TransformFromCopy(mobject, target_mobject, **kwargs)

Type: ReplacementTransform

Same parameters

class TransformFromCopyExample(Scene):
    def construct(self):
        mobject = RegularPolygon(3).scale(2)

        self.add(mobject)

        for n in range(4,9):
            self.play(
                TransformFromCopy(
                    mobject,
                    RegularPolygon(n).scale(2)
                )
            )

        self.wait(0.3)

Clockwise Transform

class manimlib.animation.transform.ClockwiseTransform(mobject, target_mobject, **kwargs)

Type: Transform

Same parameters

CONFIG parameters

"path_arc": -np.pi
class ClockwiseTransformExample(Scene):
    def construct(self):
        polygons = VGroup(
              *[RegularPolygon(n).scale(0.7) for n in range(3,9)]
        ).arrange_submobjects(RIGHT,buff=1)

        self.add(polygons[0])

        for i in range(len(polygons)-1):
            self.play(
                ClockwiseTransform(
                    polygons[0],
                    polygons[i+1]
                )
            )

        self.wait(0.3)

Counterclockwise Transform

class manimlib.animation.transform.CounterclockwiseTransform(mobject, target_mobject, **kwargs)

Type: Transform

Same parameters

CONFIG parameters

"path_arc": np.pi
class CounterclockwiseTransformExample(Scene):
    def construct(self):
        polygons = VGroup(
            *[RegularPolygon(n).scale(0.7) for n in range(3,9)]
        ).arrange_submobjects(RIGHT,buff=1)

        self.add(polygons[0])

        for i in range(len(polygons)-1):
            self.play(
                CounterclockwiseTransform(
                    polygons[0],
                    polygons[i+1]
                )
            )

        self.wait(0.3)

Move To Target

class manimlib.animation.transform.MoveToTarget(mobject, **kwargs)

Type: Transform

Parameters

mobject (Mobject) -- TODO

class MoveToTargetExample(Scene):
    def construct(self):
        mobject=Square()
        mobject.generate_target()
        VGroup(mobject,mobject.target)\
            .arrange_submobjects(RIGHT,buff=3)

        mobject.target.rotate(PI/4)\
                      .scale(2)\
                      .set_stroke(PURPLE,9)\
                      .set_fill(ORANGE,1)

        self.add(mobject)
        self.wait(0.3)

        self.play(MoveToTarget(mobject))
        self.wait(0.3)

Apply Method

class manimlib.animation.transform.ApplyMethod(method, *args, **kwargs)

Type: Transform

Parameters

method (Method) -- mobject.method,*args

CONFIG parameters

"submobject_mode": "all_at_once"
class ApplyMethodExample(Scene):
    def construct(self):
        dot = Dot()
        text = TextMobject("Text")

        dot.next_to(text,LEFT)

        self.add(text,dot)

        self.play(ApplyMethod(text.scale,3,{"about_point":dot.get_center()}))
        #                                  --------------------------------
        #                                          Optional parameters

        self.wait(0.3)

Apply Pointwise Function

class manimlib.animation.transform.ApplyPointwiseFunction(function, mobject, **kwargs)

Type: ApplyMethod

Parameters
  • function (Function) -- TODO

  • mobject (Mobject) -- TODO

CONFIG parameters

"run_time": DEFAULT_POINTWISE_FUNCTION_RUN_TIME # See constants.
class ApplyPointwiseFunctionExample(Scene):
    def construct(self):
        text = TextMobject("Text")

        self.add(text)

        def spread_out(p):
            p = p + 2*DOWN
            return (FRAME_X_RADIUS+FRAME_Y_RADIUS)*p/get_norm(p)
            #      -------------------------------
            #          See manimlib/constants.py

        self.play(
            ApplyPointwiseFunction(spread_out, text)
        )

Fade To Color

class manimlib.animation.transform.FadeToColor(mobject, color, **kwargs)

Type: ApplyMethod

Parameters
  • mobject (Mobject) -- TODO

  • color (Color) -- See color palette or hexadecimal color

class FadeToColorExample(Scene):
    def construct(self):
        text = TextMobject("Text")\
               .set_width(FRAME_WIDTH)

        colors=[RED,PURPLE,GOLD,TEAL]

        self.add(text)

        for color in colors:
            self.play(FadeToColor(text,color))

        self.wait(0.3)

Scale In Place

class manimlib.animation.transform.ScaleInPlace(mobject, scale_factor, **kwargs)

Type: ApplyMethod

Parameters
  • mobject (Mobject) -- TODO

  • scale_factor (Scale factor) -- TODO

class ScaleInPlaceExample(Scene):
    def construct(self):
        text = TextMobject("Text")\
               .set_width(FRAME_WIDTH/2)

        scale_factors=[2,0.3,0.6,2]

        self.add(text)

        for scale_factor in scale_factors:
            self.play(ScaleInPlace(text,scale_factor))

        self.wait(0.3)

Restore

class manimlib.animation.transform.Restore(mobject, **kwargs)

Type: ApplyMethod

Parameters

mobject (Mobject) -- TODO

class RestoreExample(Scene):
    def construct(self):
        text = TextMobject("Original")\
               .set_width(FRAME_WIDTH/2)

        text.save_state()

        text_2 = TextMobject("Modified")\
               .set_width(FRAME_WIDTH/1.5)\
               .set_color(ORANGE)\
               .to_corner(DL)

        self.add(text)

        self.play(Transform(text,text_2))
        self.play(
            text.shift,RIGHT,
            text.rotate,PI/4
            )
        self.play(Restore(text))

        self.wait(0.7)

Apply Function

class manimlib.animation.transform.ApplyFunction(function, mobject, **kwargs)

Type: Transform

Parameters
  • function (Function) -- TODO

  • mobject (Mobject) -- TODO

CONFIG parameters

"submobject_mode": "all_at_once",
class ApplyFunctionExample(Scene):
    def construct(self):
        text = TextMobject("Text")\
               .to_corner(DL)

        self.add(text)

        def apply_function(mob):
            mob.scale(2)
            mob.to_corner(UR)
            mob.rotate(PI/4)
            mob.set_color(RED)
            return mob

        self.play(
            ApplyFunction(
                apply_function,
                text
            )
        )

        self.wait(0.3)

Complex Function

class manimlib.animation.transform.ComplexFunction(function, mobject, **kwargs)

Type: ApplyPointwiseFunction

Parameters
  • function (Function) -- TODO

  • mobject (Mobject) -- TODO

Cyclic Replace

class manimlib.animation.transform.CyclicReplace(*mobjects, **kwargs)

Type: Transform

Parameters

*mobjects (List of Mobjects) --

CONFIG parameters

"path_arc": np.pi / 2

Transform Animations

class manimlib.animation.transform.TransformAnimations(start_anim, end_anim, **kwargs)

Type: Transform

Parameters
  • start_anim (Start animation) -- TODO

  • end_anim (End animation) -- TODO

CONFIG parameters

"rate_func": squish_rate_func(smooth)