Repository: ManimCommunity/manim
File: manim/animation/transform.py (Python)

Code before:
        alpha: float,
    ) -> "Transform":
        submobject.interpolate(starting_submobject, target_copy, alpha, self.path_func)
        return self


class ReplacementTransform(Transform):
    """Replace the mobject with target_mobject (like Transform does), and shows the target_mobject (whereas Transform shows the mobject)

    Fades one mobject into another. Transform M1 is shown M2 doies not change, only M1

        Parameters
        ----------
        mobject
            The starting :class:`~.Mobject`.
        target_mobject
            The target :class:`~.Mobject`.
        kwargs
            Further keyword arguments are passed to the parent class.

        Examples
        --------

        .. manim:: ReplacementTransformOrTransform

            class ReplacementTransformOrTransform(Scene):
                def construct(self):
                    # Set the context
                    text_0 = Tex("ReplacementTransform vs Transform", color = BLUE).scale(0.9).shift(2.5*UP)
                    self.play(Write(text_0))
                    text_1 = Tex("Text no. 1").shift(UP + 2*LEFT)
                    text_2 = Tex("Text no. 2").next_to(text_1, DOWN)
                    text_3 = Tex("Text no. 3").next_to(text_2, DOWN)
                    text_4 = Tex("Text no. 4").next_to(text_1, 5*RIGHT)
                    text_5 = Tex("Text no. 5").next_to(text_4, DOWN)
                    text_6 = Tex("Text no. 6").next_to(text_5, DOWN)
                    self.play(Write(text_1))
                    self.play(Write(text_2))
                    self.play(Write(text_3))
                    self.play(Write(text_4))
                    self.play(Write(text_5))
                    self.play(Write(text_6))
                    self.wait()
                    # Explanation between ReplacementTransform and Transform
                    text_7 = Tex("ReplacementTransform \"Text no. 1\" with \"Text no. 2\".", color = BLUE).scale(0.5).shift(1.5*DOWN + 4*LEFT)
                    self.play(Write(text_7))
                    self.play(ReplacementTransform(text_1, text_2))
                    text_8 = Tex("ReplacementTransform \"Text no. 2\" with \"Text no. 3\".", color = BLUE).scale(0.5).next_to(text_7, DOWN)
                    self.play(Write(text_8))
                    self.play(ReplacementTransform(text_2, text_3))
                    text_9 = Tex("FadeOut \"Text no. 3\".", color = BLUE).scale(0.5).next_to(text_8, DOWN)

Review comment (suggestion):
This example seems like a little excessive just to highlight the difference between the two animations. Plus, writing the latex and the animations would add a significant amount of time needed to build the docs. 

I think it could be be done neatly using squares.

Code after:
        alpha: float,
    ) -> "Transform":
        submobject.interpolate(starting_submobject, target_copy, alpha, self.path_func)
        return self


class ReplacementTransform(Transform):
    """Replaces and morphs a mobject into a target mobject.

    Parameters
    ----------
    mobject
        The starting :class:`~.Mobject`.
    target_mobject
        The target :class:`~.Mobject`.
    kwargs
        Further keyword arguments that are passed to :class:`Transform`.

    Examples
    --------

    .. manim:: ReplacementTransformOrTransform
        :quality: low

        class ReplacementTransformOrTransform(Scene):
            def construct(self):
                # set up the numbers
                r_transform = VGroup(*[Integer(i) for i in range(1,4)])
                text_1 = Text("ReplacementTransform", color=RED)
                r_transform.add(text_1)

                transform = VGroup(*[Integer(i) for i in range(4,7)])
                text_2 = Text("Transform", color=BLUE)
                transform.add(text_2)

                ints = VGroup(r_transform, transform)
                texts = VGroup(text_1, text_2).scale(0.75)
                r_transform.arrange(direction=UP, buff=1)
                transform.arrange(direction=UP, buff=1)

                ints.arrange(buff=2)
                self.add(ints, texts)

                # The mobs replace each other and none are left behind
                self.play(ReplacementTransform(r_transform[0], r_transform[1]))
                self.play(ReplacementTransform(r_transform[1], r_transform[2]))

                # The mobs linger after the Transform()
                self.play(Transform(transform[0], transform[1]))
                self.play(Transform(transform[1], transform[2]))
                self.wait()