
    ljSy                    b   d Z ddlmZ g dZddlZddlZddlmZmZm	Z	 ddl
mZmZ ddlZddlmZ ddlmZmZ d	d
lmZ d	dlmZ d	dlmZmZmZmZmZ d	dlmZm Z  d	dl!m"Z"m#Z# d	dl$m%Z%m&Z& erd	dl'm(Z( d	dl
m)Z)m*Z*  G d de          Z+ G d de+          Z, G d de+          Z- G d de+          Z. G d de+          Z/ G d de+          Z0 G d de0          Z1 G d  d!e+          Z2 G d" d#e2          Z3 G d$ d%e3          Z4 G d& d'e2          Z5 G d( d)e2          Z6 G d* d+e6          Z7 G d, d-e2          Z8 G d. d/e+          Z9 G d0 d1e3          Z: G d2 d3e2          Z; G d4 d5e+          Z< G d6 d7e<          Z= G d8 d9e+          Z> G d: d;e+          Z? G d< d=e?          Z@dS )>z1Animations transforming one mobject into another.    )annotations)	TransformReplacementTransformTransformFromCopyClockwiseTransformCounterclockwiseTransformMoveToTargetApplyMethodApplyPointwiseFunctionApplyPointwiseFunctionToCenterFadeToColorFadeTransformFadeTransformPiecesScaleInPlaceShrinkToCenterRestoreApplyFunctionApplyMatrixApplyComplexFunctionCyclicReplaceSwapTransformAnimationsN)CallableIterableSequence)TYPE_CHECKINGAny)MethodWithArgs)OpenGLGroupOpenGLMobject   )config)	Animation)#DEFAULT_POINTWISE_FUNCTION_RUN_TIMEDEGREESORIGINOUTRendererType)GroupMobject)path_along_arcpath_along_circles)smoothsquish_rate_func)Scene)Point3DLikePoint3DLike_Arrayc                       e Zd ZdZdddeddfd* fdZed+d            Zej        d,d            Zed-d            Z	e	j        d.d            Z	d/ fdZ
d0dZd1 fdZd2d!Zd3d#Zd4d)Z xZS )5r   uD  A Transform transforms a Mobject into a target Mobject.

    Parameters
    ----------
    mobject
        The :class:`.Mobject` to be transformed. It will be mutated to become the ``target_mobject``.
    target_mobject
        The target of the transformation.
    path_func
        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 :mod:`.utils.paths`.
    path_arc
        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 :func:`manim.utils.paths.path_along_arc`.
    path_arc_axis
        The axis to rotate along if using a circular path arc, see ``path_arc_centers``.
    path_arc_centers
        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
        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
    --------

    .. manim :: TransformPathArc

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

    See also
    --------
    :class:`~.ReplacementTransform`, :meth:`~.Mobject.interpolate`, :meth:`~.Mobject.align_data`
    Nr   FmobjectMobject | Nonetarget_mobject	path_funcCallable | Nonepath_arcfloatpath_arc_axis
np.ndarraypath_arc_centers&Point3DLike | Point3DLike_Array | None$replace_mobject_with_target_in_sceneboolreturnNonec                   || _         || _        || _        ||| _        n'| j         t	          || j        | j                   | _        || _        ||nt                      | _         t                      j	        |fi | d S N)
r:   r<   r8   r6   r,   r>   r*   r5   super__init__)
selfr3   r5   r6   r8   r:   r<   r>   kwargs	__class__s
            T/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/animation/transform.pyrE   zTransform.__init__   s     *7HX'  '0DNN"./%" DN 1 	1 -8NNgii 	 	++F+++++    c                    | j         S rC   )	_path_arcrF   s    rI   r8   zTransform.path_arc   s
    ~rJ   c                T    || _         t          | j         | j                  | _        d S )N)	arc_angleaxis)rL   r+   r:   
_path_func)rF   r8   s     rI   r8   zTransform.path_arc   s.    !(n#
 
 
rJ   SCallable[[Iterable[np.ndarray], Iterable[np.ndarray], float], Iterable[np.ndarray]]c                    | j         S rC   rQ   rM   s    rI   r6   zTransform.path_func   s     rJ   c                    |	|| _         d S d S rC   rT   )rF   r6   s     rI   r6   zTransform.path_func   s      'DOOO ! rJ   c                h   |                                  | _        | j                                        | _        t          j        t          j        k    r | j        	                    | j                   n| j        
                    | j                   t                                                       d S rC   )create_targetr5   copytarget_copyr"   rendererr(   OPENGLr3   align_data_and_family
align_datarD   beginrF   rH   s    rI   r^   zTransform.begin   s     #0022.3355 ?l111L..t/?@@@@L##D$4555rJ   Mobject | OpenGLMobjectc                    | j         S rC   )r5   rM   s    rI   rW   zTransform.create_target   s     ""rJ   scener/   c                    t                                          |           | j        r"|                    | j        | j                   d S d S rC   )rD   clean_up_from_scener>   replacer3   r5   )rF   rb   rH   s     rI   rd   zTransform.clean_up_from_scene   sO    ##E***4 	=MM$,(;<<<<<	= 	=rJ   Sequence[Mobject]c                6    | j         | j        | j        | j        gS rC   )r3   starting_mobjectr5   rY   rM   s    rI   get_all_mobjectszTransform.get_all_mobjects   s#    L!	
 	
rJ   Iterable[tuple]c                    | j         | j        | j        g}t          j        t
          j        k    rt          d |D             ddiS t          d |D             ddiS )Nc              3  >   K   | ]}|                                 V  d S rC   )
get_family.0mobs     rI   	<genexpr>z4Transform.get_all_families_zipped.<locals>.<genexpr>   s,      ::c))::::::rJ   strictTc              3  >   K   | ]}|                                 V  d S rC   )family_members_with_pointsrn   s     rI   rq   z4Transform.get_all_families_zipped.<locals>.<genexpr>   s.      FF#S3355FFFFFFrJ   )r3   rh   rY   r"   rZ   r(   r[   zip)rF   mobss     rI   get_all_families_zippedz!Transform.get_all_families_zipped   sp    L!

 ?l111::T:::H4HHHFFFFFTtTTTrJ   
submobjectr*   starting_submobjectrY   alphac                @    |                     |||| j                   | S rC   )interpolater6   )rF   rx   ry   rY   rz   s        rI   interpolate_submobjectz Transform.interpolate_submobject   s&     	2KWWWrJ   )r3   r4   r5   r4   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   )r@   r9   )r8   r9   r@   rA   )r@   rR   )r6   rR   r@   rA   r@   rA   )r@   r`   )rb   r/   r@   rA   r@   rf   )r@   rj   )
rx   r*   ry   r*   rY   r*   rz   r9   r@   r   )__name__
__module____qualname____doc__r'   rE   propertyr8   setterr6   r^   rW   rd   ri   rw   r}   __classcell__rH   s   @rI   r   r   9   sz       J J^ *.%)$'CG5:, , , , , , ,B    X _
 
 
 _
    X ( ( ( (     # # # #
= = = = = =

 
 
 
U U U U       rJ   r   c                  $     e Zd ZdZd fdZ xZS )	r   a>  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()

    r3   r*   r5   r@   rA   c                B     t                      j        ||fddi| d S )Nr>   TrD   rE   rF   r3   r5   rG   rH   s       rI   rE   zReplacementTransform.__init__,  sB    ^	
 	
JN	
RX	
 	
 	
 	
 	
rJ   r3   r*   r5   r*   r@   rA   r   r   r   r   rE   r   r   s   @rI   r   r      sH        - -^
 
 
 
 
 
 
 
 
 
rJ   r   c                  0     e Zd ZdZd fdZd fd
Z xZS )r   z^Preserves a copy of the original VMobject and transforms only it's copy to the target VMobjectr3   r*   r5   r@   rA   c                >     t                      j        ||fi | d S rC   r   r   s       rI   rE   zTransformFromCopy.__init__5  s*    ;;F;;;;;rJ   rz   r9   c                P    t                                          d|z
             d S N   )rD   r|   rF   rz   rH   s     rI   r|   zTransformFromCopy.interpolate8  s%    AI&&&&&rJ   r   rz   r9   r@   rA   )r   r   r   r   rE   r|   r   r   s   @rI   r   r   2  sa        hh< < < < < <' ' ' ' ' ' ' ' ' 'rJ   r   c                  4     e Zd ZdZej         fd
 fd	Z xZS )r   a  Transforms the points of a mobject along a clockwise oriented arc.

    See also
    --------
    :class:`.Transform`, :class:`.CounterclockwiseTransform`

    Examples
    --------

    .. manim:: ClockwiseExample

        class ClockwiseExample(Scene):
            def construct(self):
                dl, dr = Dot(), Dot()
                sl, sr = Square(), Square()

                VGroup(dl, sl).arrange(DOWN).shift(2*LEFT)
                VGroup(dr, sr).arrange(DOWN).shift(2*RIGHT)

                self.add(dl, dr)
                self.wait()
                self.play(
                    ClockwiseTransform(dl, sl),
                    Transform(dr, sr)
                )
                self.wait()

    r3   r*   r5   r8   r9   r@   rA   c                B     t                      j        ||fd|i| d S Nr8   r   rF   r3   r5   r8   rG   rH   s        rI   rE   zClockwiseTransform.__init__Z  1     	.NN8NvNNNNNrJ   r3   r*   r5   r*   r8   r9   r@   rA   r   r   r   r   nppirE   r   r   s   @rI   r   r   <  sa         B 5&	O O O O O O O O O O OrJ   r   c                  2     e Zd ZdZej        fd
 fd	Z xZS )r   a  Transforms the points of a mobject along a counterclockwise oriented arc.

    See also
    --------
    :class:`.Transform`, :class:`.ClockwiseTransform`

    Examples
    --------

    .. manim:: CounterclockwiseTransform_vs_Transform

        class CounterclockwiseTransform_vs_Transform(Scene):
            def construct(self):
                # set up the numbers
                c_transform = VGroup(DecimalNumber(number=3.141, num_decimal_places=3), DecimalNumber(number=1.618, num_decimal_places=3))
                text_1 = Text("CounterclockwiseTransform", color=RED)
                c_transform.add(text_1)

                transform = VGroup(DecimalNumber(number=1.618, num_decimal_places=3), DecimalNumber(number=3.141, num_decimal_places=3))
                text_2 = Text("Transform", color=BLUE)
                transform.add(text_2)

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

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

                # The mobs move in clockwise direction for ClockwiseTransform()
                self.play(CounterclockwiseTransform(c_transform[0], c_transform[1]))

                # The mobs move straight up for Transform()
                self.play(Transform(transform[0], transform[1]))

    r3   r*   r5   r8   r9   r@   rA   c                B     t                      j        ||fd|i| d S r   r   r   s        rI   rE   z"CounterclockwiseTransform.__init__  r   rJ   r   r   r   s   @rI   r   r   d  s_        $ $T %	O O O O O O O O O O OrJ   r   c                  ,     e Zd ZdZd fdZddZ xZS )	r	   a  Transforms a mobject to the mobject stored in its ``target`` attribute.

    After calling the :meth:`~.Mobject.generate_target` method, the :attr:`target`
    attribute of the mobject is populated with a copy of it. After modifying the attribute,
    playing the :class:`.MoveToTarget` animation transforms the original mobject
    into the modified one stored in the :attr:`target` attribute.

    Examples
    --------

    .. manim:: MoveToTargetExample

        class MoveToTargetExample(Scene):
            def construct(self):
                c = Circle()

                c.generate_target()
                c.target.set_fill(color=GREEN, opacity=0.5)
                c.target.shift(2*RIGHT + UP).scale(0.5)

                self.add(c)
                self.play(MoveToTarget(c))

    r3   r*   r@   rA   c                r    |                      |            t                      j        ||j        fi | d S rC   )check_validity_of_inputrD   rE   targetrF   r3   rG   rH   s      rI   rE   zMoveToTarget.__init__  s@    $$W---'.;;F;;;;;rJ   c                D    t          |d          st          d          d S )Nr   z8MoveToTarget called on mobjectwithout attribute 'target')hasattr
ValueError)rF   r3   s     rI   r   z$MoveToTarget.check_validity_of_input  s3    w)) 	J  	 	rJ   r3   r*   r@   rA   )r   r   r   r   rE   r   r   r   s   @rI   r	   r	     s[         2< < < < < <       rJ   r	   c                  ,     e Zd Zd	 fdZd
 fdZ xZS )_MethodAnimationr3   r*   methodslist[MethodWithArgs]r@   rA   c                X    || _         t                                          |           d S rC   )r   rD   rE   )rF   r3   r   rH   s      rI   rE   z_MethodAnimation.__init__  s(    !!!!!rJ   c                    | j         D ]'} |j        j        | j        g|j        R i |j         (t                                                       d S rC   )r   method__func__r3   argsrG   rD   finish)rF   itemrH   s     rI   r   z_MethodAnimation.finish  s^    L 	J 	JD DK I	IIIT[IIIIrJ   )r3   r*   r   r   r@   rA   r~   )r   r   r   rE   r   r   r   s   @rI   r   r     s[        " " " " " "         rJ   r   c                  4     e Zd ZdZd
 fdZd
dZdd	Z xZS )r
   a  Animates a mobject by applying a method.

    Note that only the method needs to be passed to this animation,
    it is not required to pass the corresponding mobject. Furthermore,
    this animation class only works if the method returns the modified
    mobject.

    Parameters
    ----------
    method
        The method that will be applied in the animation.
    args
        Any positional arguments to be passed when applying the method.
    kwargs
        Any keyword arguments passed to :class:`~.Transform`.

    r   r   r@   rA   c                    |                      |           || _        || _         t                      j        |j        fi | d S rC   )r   r   method_argsrD   rE   __self__)rF   r   r   rG   rH   s       rI   rE   zApplyMethod.__init__  sO     	$$V,,,33F33333rJ   c                    t          j        |          st          d          t          |j        t
          t          f          sJ d S )NzJWhoops, looks like you accidentally invoked the method you want to animate)inspectismethodr   
isinstancer   r*   r    )rF   r   s     rI   r   z#ApplyMethod.check_validity_of_input  sQ    '' 	1   &/G]+CDDDDDDDrJ   r*   c                   | j         }t          | j                  }t          |          dk    r0t	          |d         t
                    r|                                }ni }|j                                        } |j	        |g|R i | |S )Nr   )
r   listr   lenr   dictpopr   rX   r   )rF   r   r   method_kwargsr   s        rI   rW   zApplyMethod.create_target  s    D$%%t99q==ZR$77= HHJJMMM%%''7777777rJ   )r   r   r@   rA   )r@   r*   )r   r   r   r   rE   r   rW   r   r   s   @rI   r
   r
     ss         $4 4 4 4 4 4E E E E       rJ   r
   c                  (     e Zd ZdZefd fd
Z xZS )r   a  Animation that applies a pointwise function to a mobject.

    Examples
    --------

    .. manim:: WarpSquare
        :quality: low

        class WarpSquare(Scene):
            def construct(self):
                square = Square()
                self.play(
                    ApplyPointwiseFunction(
                        lambda point: complex_to_R3(np.exp(R3_to_complex(point))), square
                    )
                )
                self.wait()

    functiontypes.MethodTyper3   r*   run_timer9   r@   rA   c                L     t                      j        |j        |fd|i| d S )Nr   )rD   rE   apply_function)rF   r   r3   r   rG   rH   s        rI   rE   zApplyPointwiseFunction.__init__  s5     	/WWHWPVWWWWWrJ   )r   r   r3   r*   r   r9   r@   rA   )r   r   r   r   r$   rE   r   r   s   @rI   r   r     s\         0 >	X X X X X X X X X X XrJ   r   c                  ,     e Zd Zd	 fdZd
 fdZ xZS )r   r   r   r3   r*   r@   rA   c                T    || _          t                      j        |j        fi | d S rC   )r   rD   rE   move_torF   r   r3   rG   rH   s       rI   rE   z'ApplyPointwiseFunctionToCenter.__init__  s1     33F33333rJ   c                    |                      | j                                                  g| _        t	                                                       d S rC   )r   r3   
get_centerr   rD   r^   r_   s    rI   r^   z$ApplyPointwiseFunctionToCenter.begin  s=     MM$,*A*A*C*CDDErJ   r   r   r3   r*   r@   rA   r~   )r   r   r   rE   r^   r   r   s   @rI   r   r     s[        4 4 4 4 4 4         rJ   r   c                  $     e Zd ZdZd	 fdZ xZS )
r   a  Animation that changes color of a mobject.

    Examples
    --------

    .. manim:: FadeToColorExample

        class FadeToColorExample(Scene):
            def construct(self):
                self.play(FadeToColor(Text("Hello World!"), color=RED))

    r3   r*   colorstrr@   rA   c                H     t                      j        |j        |fi | d S rC   )rD   rE   	set_color)rF   r3   r   rG   rH   s       rI   rE   zFadeToColor.__init__-  s-    *E<<V<<<<<rJ   )r3   r*   r   r   r@   rA   r   r   s   @rI   r   r     sG         = = = = = = = = = =rJ   r   c                  $     e Zd ZdZd	 fdZ xZS )
r   a  Animation that scales a mobject by a certain factor.

    Examples
    --------

    .. manim:: ScaleInPlaceExample

        class ScaleInPlaceExample(Scene):
            def construct(self):
                self.play(ScaleInPlace(Text("Hello World!"), 2))

    r3   r*   scale_factorr9   r@   rA   c                H     t                      j        |j        |fi | d S rC   )rD   rE   scale)rF   r3   r   rG   rH   s       rI   rE   zScaleInPlace.__init__?  s,    ???????rJ   )r3   r*   r   r9   r@   rA   r   r   s   @rI   r   r   1  sQ         @ @ @ @ @ @ @ @ @ @rJ   r   c                  $     e Zd ZdZd fdZ xZS )r   a  Animation that makes a mobject shrink to center.

    Examples
    --------

    .. manim:: ShrinkToCenterExample

        class ShrinkToCenterExample(Scene):
            def construct(self):
                self.play(ShrinkToCenter(Text("Hello World!")))

    r3   r*   r@   rA   c                >     t                      j        |dfi | d S Nr   r   r   s      rI   rE   zShrinkToCenter.__init__Q  s*    !..v.....rJ   r   r   r   s   @rI   r   r   C  sG         / / / / / / / / / /rJ   r   c                  $     e Zd ZdZd fdZ xZS )r   aT  Transforms a mobject to its last saved state.

    To save the state of a mobject, use the :meth:`~.Mobject.save_state` method.

    Examples
    --------

    .. manim:: RestoreExample

        class RestoreExample(Scene):
            def construct(self):
                s = Square()
                s.save_state()
                self.play(FadeIn(s))
                self.play(s.animate.set_color(PURPLE).set_opacity(0.5).shift(2*LEFT).scale(3))
                self.play(s.animate.shift(5*DOWN).rotate(PI/4))
                self.wait()
                self.play(Restore(s), run_time=2)

    r3   r*   r@   rA   c                F     t                      j        |j        fi | d S rC   )rD   rE   restorer   s      rI   rE   zRestore.__init__k  s*    33F33333rJ   r   r   r   s   @rI   r   r   U  sG         *4 4 4 4 4 4 4 4 4 4rJ   r   c                  (     e Zd Zd
 fdZdd	Z xZS )r   r   r   r3   r*   r@   rA   c                J    || _          t                      j        |fi | d S rC   )r   rD   rE   r   s       rI   rE   zApplyFunction.__init__p  s/     ++F+++++rJ   r   c                    |                      | j                                                  }t          |t          t
          f          st          d          |S )NzDFunctions passed to ApplyFunction must return object of type Mobject)r   r3   rX   r   r*   r    	TypeError)rF   r   s     rI   rW   zApplyFunction.create_targett  sT    t|002233&7M":;; 	V   rJ   r   )r@   r   )r   r   r   rE   rW   r   r   s   @rI   r   r   o  sQ        , , , , , ,       rJ   r   c                  0     e Zd ZdZefd fd	Zdd
Z xZS )r   a{  Applies a matrix transform to an mobject.

    Parameters
    ----------
    matrix
        The transformation matrix.
    mobject
        The :class:`~.Mobject`.
    about_point
        The origin point for the transform. Defaults to ``ORIGIN``.
    kwargs
        Further keyword arguments that are passed to :class:`ApplyPointwiseFunction`.

    Examples
    --------

    .. manim:: ApplyMatrixExample

        class ApplyMatrixExample(Scene):
            def construct(self):
                matrix = [[1, 1], [0, 2/3]]
                self.play(ApplyMatrix(matrix, Text("Hello World!")), ApplyMatrix(matrix, NumberPlane()))

    matrixr;   r3   r*   about_pointr@   rA   c                x    |                                fd} t                      j        ||fi | d S )Nc                D    t          j        | z
  j                  z   S rC   )r   dotT)pr   r   s    rI   funcz"ApplyMatrix.__init__.<locals>.func  s     6!k/6844{BBrJ   )initialize_matrixrD   rE   )rF   r   r3   r   rG   r   rH   s    ` `  rI   rE   zApplyMatrix.__init__  sg     ''//	C 	C 	C 	C 	C 	C 	w11&11111rJ   c                    t          j        |          }|j        dk    r"t          j        d          }||d dd df<   |}n|j        dk    rt	          d          |S )N)r!   r!      r!   )r   r   zMatrix has bad dimensions)r   arrayshapeidentityr   )rF   r   
new_matrixs      rI   r   zApplyMatrix.initialize_matrix  si    &!!<6!!QJ!'Jrr2A2vFF\V##8999rJ   )r   r;   r3   r*   r   r;   r@   rA   )r   r;   r@   r;   )r   r   r   r   r&   rE   r   r   r   s   @rI   r   r   }  se         : #)	2 2 2 2 2 2 2       rJ   r   c                  ,     e Zd Zd	 fdZd
 fdZ xZS )r   r   r   r3   r*   r@   rA   c                Z    || _         |j        } t                      j        ||fi | d S rC   )r   apply_complex_functionrD   rE   )rF   r   r3   rG   r   rH   s        rI   rE   zApplyComplexFunction.__init__  s9     /44V44444rJ   c                    |                      t          d                    }t          j        |          j        | _        t                                                       d S r   )r   complexr   logimagr8   rD   _init_path_func)rF   func1rH   s     rI   r   z$ApplyComplexFunction._init_path_func  sH    gajj))u*!!!!!rJ   r   r~   )r   r   r   rE   r   r   r   s   @rI   r   r     s[        5 5 5 5 5 5
" " " " " " " " " "rJ   r   c                  8     e Zd ZdZdez  dd fd
ZddZ xZS )r   a  An animation moving mobjects cyclically.

    In particular, this means: the first mobject takes the place
    of the second mobject, the second one takes the place of
    the third mobject, and so on. The last mobject takes the
    place of the first one.

    Parameters
    ----------
    mobjects
        List of mobjects to be transformed.
    path_arc
        The angle of the arc (in radians) that the mobjects will follow to reach
        their target.
    kwargs
        Further keyword arguments that are passed to :class:`.Transform`.

    Examples
    --------
    .. manim :: CyclicReplaceExample

        class CyclicReplaceExample(Scene):
            def construct(self):
                group = VGroup(Square(), Circle(), Triangle(), Star())
                group.arrange(RIGHT)
                self.add(group)

                for _ in range(4):
                    self.play(CyclicReplace(*group))
    Z   )r8   mobjectsr*   r8   r9   r@   rA   c               f    t          | | _         t                      j        | j        fd|i| d S r   )r)   grouprD   rE   )rF   r8   r   rG   rH   s       rI   rE   zCyclicReplace.__init__  s=     H%
AAhA&AAAAArJ   r)   c                    | j                                         }|d         g|d d         }t          || j         d          D ]\  }}|                    |           |S )Nr   Trr   )r   rX   ru   r   )rF   r   cycled_targetsm1m2s        rI   rW   zCyclicReplace.create_target  sf    "" *3vcrc{3.$*TBBB 	 	FBJJrNNNNrJ   )r   r*   r8   r9   r@   rA   )r@   r)   )r   r   r   r   r%   rE   rW   r   r   s   @rI   r   r     sw         @ 57LB B B B B B B B       rJ   r   c                      e Zd ZdS )r   N)r   r   r    rJ   rI   r   r     s        DrJ   r   c                  B     e Zd Z ee          fd fdZd fdZ xZS )r   
start_animr#   end_anim	rate_funcr   r@   rA   c                   || _         || _        d|v r|                    d          | _        nt	          |j        |j                  | _        ||fD ]}|                    | j                   |j        |j        |j                                        |j                                        k    ra|j                            |j                   ||fD ]=}t          |t                    r&|j        |j                            |j                   > t                      j        |j        |j        fd|i| | j        |_        | j        |_        d S )Nr   r  )r	  r
  r   r   maxset_run_timerh   get_num_pointsr]   r   r   r5   rD   rE   r3   )rF   r	  r
  r  rG   animrH   s         rI   rE   zTransformAnimations.__init__  sx    % "JJz22DMM
 3X5FGGDM( 	- 	-Ddm,,,,'3)5+::<<(7799: : '2283LMMM"H, J JdI.. J43H3T)44T5HIII 0	
 	
<E	
IO	
 	
 	
 "2
.rJ   rz   r9   c                    | j                             |           | j                            |           t                                          |           d S rC   )r	  r|   r
  rD   r   s     rI   r|   zTransformAnimations.interpolate  sM    ##E***!!%(((E"""""rJ   )r	  r#   r
  r#   r  r   r@   rA   r   )r   r   r   r.   r-   rE   r|   r   r   s   @rI   r   r     sq        
 /.v66	/ / / / / / /B# # # # # # # # # #rJ   r   c                  D     e Zd ZdZd fd	Zd Zd Zdd	Zd
 Zd Z	 xZ
S )r   aV  Fades one mobject into another.

    Parameters
    ----------
    mobject
        The starting :class:`~.Mobject`.
    target_mobject
        The target :class:`~.Mobject`.
    stretch
        Controls whether the target :class:`~.Mobject` is stretched during
        the animation. Default: ``True``.
    dim_to_match
        If the target mobject is not stretched automatically, this allows
        to adjust the initial scale of the target :class:`~.Mobject` while
        it is shifted in. Setting this to 0, 1, and 2, respectively,
        matches the length of the target with the length of the starting
        :class:`~.Mobject` in x, y, and z direction, respectively.
    kwargs
        Further keyword arguments are passed to the parent class.

    Examples
    --------

    .. manim:: DifferentFadeTransforms

        class DifferentFadeTransforms(Scene):
            def construct(self):
                starts = [Rectangle(width=4, height=1) for _ in range(3)]
                VGroup(*starts).arrange(DOWN, buff=1).shift(3*LEFT)
                targets = [Circle(fill_opacity=1).scale(0.25) for _ in range(3)]
                VGroup(*targets).arrange(DOWN, buff=1).shift(3*RIGHT)

                self.play(*[FadeIn(s) for s in starts])
                self.play(
                    FadeTransform(starts[0], targets[0], stretch=True),
                    FadeTransform(starts[1], targets[1], stretch=False, dim_to_match=0),
                    FadeTransform(starts[2], targets[2], stretch=False, dim_to_match=1)
                )

                self.play(*[FadeOut(mobj) for mobj in self.mobjects])

    Tr   c                L   || _         || _        || _        |                                 t          j        t          j        k    r#t          ||	                                          }n"t          ||	                                          } t                      j        |fi | d S rC   )to_add_on_completionstretchdim_to_match
save_stater"   rZ   r(   r[   r   rX   r)   rD   rE   )rF   r3   r5   r  r  rG   r   rH   s          rI   rE   zFadeTransform.__init__F  s    $2!(?l111)<)<)>)>??EE'>#6#6#8#899E))&)))))rJ   c                    | j                                         | _        t          j        |            | j        | j        }}|d         |d         f|d         |d         ffD ]\  }}|                     ||           dS )aF  Initial setup for the animation.

        The mobject to which this animation is bound is a group consisting of
        both the starting and the ending mobject. At the start, the ending
        mobject replaces the starting mobject (and is completely faded). In the
        end, it is set to be the other way around.
        r   r   N)r3   rX   ending_mobjectr#   r^   rh   ghost_to)rF   startendm0r  s        rI   r^   zFadeTransform.beginQ  s     #l//11 *D,?sa%(+c!fc!f-=> 	" 	"FBMM"b!!!!	" 	"rJ   c                    |                                 s|j        r"|                    || j        | j                   |                    d           dS )zReplaces the source by the target and sets the opacity to 0.

        If the provided target has no points, and thus a location of [0, 0, 0]
        the source will simply fade out where it currently is.
        )r  r  r   N)r  submobjectsre   r  r  set_opacity)rF   sourcer   s      rI   r  zFadeTransform.ghost_tob  s[       "" 	Yf&8 	YNN64<dFWNXXX1rJ   r@   rf   c                *    | j         | j        | j        gS rC   )r3   rh   r  rM   s    rI   ri   zFadeTransform.get_all_mobjectsm  s    L!
 	
rJ   c                *    t          j        |           S rC   )r#   rw   rM   s    rI   rw   z%FadeTransform.get_all_families_zippedt  s    0666rJ   c                    t          j        | |           |                    | j                   | j        d                                          |                    | j                   d S r   )r#   rd   remover3   r   addr  )rF   rb   s     rI   rd   z!FadeTransform.clean_up_from_scenew  s\    %dE222T\"""Q!!!		$+,,,,,rJ   )Tr   r   )r   r   r   r   rE   r^   r  ri   rw   rd   r   r   s   @rI   r   r     s        ) )V	* 	* 	* 	* 	* 	*" " ""	 	 	
 
 
 
7 7 7- - - - - - -rJ   r   c                  ,     e Zd ZdZ fdZ fdZ xZS )r   a  Fades submobjects of one mobject into submobjects of another one.

    See also
    --------
    :class:`~.FadeTransform`

    Examples
    --------
    .. manim:: FadeTransformSubmobjects

        class FadeTransformSubmobjects(Scene):
            def construct(self):
                src = VGroup(Square(), Circle().shift(LEFT + UP))
                src.shift(3*LEFT + 2*UP)
                src_copy = src.copy().shift(4*DOWN)

                target = VGroup(Circle(), Triangle().shift(RIGHT + DOWN))
                target.shift(3*RIGHT + 2*UP)
                target_copy = target.copy().shift(4*DOWN)

                self.play(FadeIn(src), FadeIn(src_copy))
                self.play(
                    FadeTransform(src, target),
                    FadeTransformPieces(src_copy, target_copy)
                )
                self.play(*[FadeOut(mobj) for mobj in self.mobjects])

    c                    | j         d                             | j         d                    t                                                       d S )Nr   r   )r3   align_submobjectsrD   r^   r_   s    rI   r^   zFadeTransformPieces.begin  s8    Q))$,q/:::rJ   c                    t          |                                |                                d          D ]'\  }}t                                          ||           (dS )zeReplaces the source submobjects by the target submobjects and sets
        the opacity to 0.
        Tr  N)ru   rm   rD   r  )rF   r!  r   sm0sm1rH   s        rI   r  zFadeTransformPieces.ghost_to  sf     F--//1B1B1D1DTRRR 	' 	'HCGGS#&&&&	' 	'rJ   )r   r   r   r   r^   r  r   r   s   @rI   r   r   ~  s[         :    ' ' ' ' ' ' ' ' 'rJ   r   )Ar   
__future__r   __all__r   typescollections.abcr   r   r   typingr   r   numpyr   manim.data_structuresr   #manim.mobject.opengl.opengl_mobjectr   r     r"   animation.animationr#   	constantsr$   r%   r&   r'   r(   mobject.mobjectr)   r*   utils.pathsr+   r,   utils.rate_functionsr-   r.   scene.scener/   r0   r1   r   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rJ   rI   <module>r<     sv   7 7 " " " " " "  0   8 8 8 8 8 8 8 8 8 8 % % % % % % % %     0 0 0 0 0 0 J J J J J J J J       + + + + + +              - , , , , , , , < < < < < < < < ; ; ; ; ; ; ; ; 8######77777777@ @ @ @ @	 @ @ @F3
 3
 3
 3
 3
9 3
 3
 3
l' ' ' ' '	 ' ' '%O %O %O %O %O %O %O %OP.O .O .O .O .O	 .O .O .Ob" " " " "9 " " "J    |   . . . . .) . . .bX X X X X[ X X X>    %;   = = = = =+ = = =$@ @ @ @ @; @ @ @$/ / / / /\ / / /$4 4 4 4 4k 4 4 44    I   0 0 0 0 0( 0 0 0f	" 	" 	" 	" 	"; 	" 	" 	"+ + + + +I + + +\	 	 	 	 	= 	 	 	
%# %# %# %# %#) %# %# %#Pa- a- a- a- a-I a- a- a-H'' '' '' '' ''- '' '' '' '' ''rJ   