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

Code before:

        class ShowWrite(Scene):
            def construct(self):
                self.play(Write(Text("Hello").scale(3)))

    .. manim:: ShowWriteReversed

        class ShowWriteReversed(Scene):
            def construct(self):
                self.play(Write(Text("Hello").scale(3), reverse=True))
    """

    def __init__(
        self,
        vmobject: Union[VMobject, OpenGLVMobject],
        rate_func: Callable[[float], float] = linear,
        reverse: bool = False,
        **kwargs,
    ) -> None:
        run_time: Optional[float] = kwargs.pop("run_time", None)
        lag_ratio: Optional[float] = kwargs.pop("lag_ratio", None)
        run_time, lag_ratio = self._set_default_config_from_length(
            vmobject, run_time, lag_ratio
        )
        self.reverse = reverse
        self.vmobject = vmobject
        super().__init__(
            vmobject,
            rate_func=rate_func,
            run_time=run_time,
            lag_ratio=lag_ratio,
            **kwargs,
        )

    def _set_default_config_from_length(
        self,
        vmobject: Union[VMobject, OpenGLVMobject],
        run_time: Optional[float],
        lag_ratio: Optional[float],
    ) -> Tuple[float, float]:
        length = len(vmobject.family_members_with_points())
        if run_time is None:
            if length < 15:
                run_time = 1
            else:
                run_time = 2
        if lag_ratio is None:
            lag_ratio = min(4.0 / length, 0.2)
        return run_time, lag_ratio

    def reverse_submobjects(self) -> None:

Review comment (suggestion):
That shouldn't be necessary, animations store the mobject they are manipulating as `self.mobject` IIRC.

Code after:

        class ShowWrite(Scene):
            def construct(self):
                self.play(Write(Text("Hello").scale(3)))

    .. manim:: ShowWriteReversed

        class ShowWriteReversed(Scene):
            def construct(self):
                self.play(Write(Text("Hello").scale(3), reverse=True))
    """

    def __init__(
        self,
        vmobject: Union[VMobject, OpenGLVMobject],
        rate_func: Callable[[float], float] = linear,
        reverse: bool = False,
        **kwargs,
    ) -> None:
        run_time: Optional[float] = kwargs.pop("run_time", None)
        lag_ratio: Optional[float] = kwargs.pop("lag_ratio", None)
        run_time, lag_ratio = self._set_default_config_from_length(
            vmobject, run_time, lag_ratio
        )
        self.reverse = reverse
        super().__init__(
            vmobject,
            rate_func=rate_func,
            run_time=run_time,
            lag_ratio=lag_ratio,
            **kwargs,
        )

    def _set_default_config_from_length(
        self,
        vmobject: Union[VMobject, OpenGLVMobject],
        run_time: Optional[float],
        lag_ratio: Optional[float],
    ) -> Tuple[float, float]:
        length = len(vmobject.family_members_with_points())
        if run_time is None:
            if length < 15:
                run_time = 1
            else:
                run_time = 2
        if lag_ratio is None:
            lag_ratio = min(4.0 / length, 0.2)
        return run_time, lag_ratio

    def reverse_submobjects(self) -> None:
        self.mobject.invert(recursive=True)