
    lj                    *   d Z ddlmZ g dZddlmZ ddlmZmZ ddl	Z
ddlmZ dd	lmZ er dd
lmZ ddlmZ ddlmZmZ ddlmZ ddl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dS )zAnimations related to movement.    )annotations)HomotopySmoothedVectorizedHomotopyComplexHomotopy	PhaseFlowMoveAlongPath)Callable)TYPE_CHECKINGAnyN   )	Animation)linear)Self)VMobject)MappingFunctionPoint3D)RateFunction)Mobjectc                  :     e Zd ZdZ	 	 dd fdZddZddZ xZS )r   a  A Homotopy.

    This is an animation transforming the points of a mobject according
    to the specified transformation function. With the parameter :math:`t`
    moving from 0 to 1 throughout the animation and :math:`(x, y, z)`
    describing the coordinates of the point of a mobject,
    the function passed to the ``homotopy`` keyword argument should
    transform the tuple :math:`(x, y, z, t)` to :math:`(x', y', z')`,
    the coordinates the original point is transformed to at time :math:`t`.

    Parameters
    ----------
    homotopy
        A function mapping :math:`(x, y, z, t)` to :math:`(x', y', z')`.
    mobject
        The mobject transformed under the given homotopy.
    run_time
        The run time of the animation.
    apply_function_kwargs
        Keyword arguments propagated to :meth:`.Mobject.apply_function`.
    kwargs
        Further keyword arguments passed to the parent class.

    Examples
    --------

    .. manim:: HomotopyExample

        class HomotopyExample(Scene):
            def construct(self):
                square = Square()

                def homotopy(x, y, z, t):
                    if t <= 0.25:
                        progress = t / 0.25
                        return (x, y + progress * 0.2 * np.sin(x), z)
                    else:
                        wave_progress = (t - 0.25) / 0.75
                        return (x, y + 0.2 * np.sin(x + 10 * wave_progress), z)

                self.play(Homotopy(homotopy, square, rate_func= linear, run_time=2))

       NhomotopyBCallable[[float, float, float, float], tuple[float, float, float]]mobjectr   run_timefloatapply_function_kwargsdict[str, Any] | Nonekwargsr   c                d    || _         ||ni | _         t                      j        |fd|i| d S )Nr   )r   r   super__init__)selfr   r   r   r   r   	__class__s         S/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/animation/movement.pyr!   zHomotopy.__init__L   sN     !%:%F!!B 	" 	>>8>v>>>>>    treturnr   c                     d fd}|S )Npr   r'   c                d    | \  }}}t          j                            |||                    S N)nparrayr   )r)   xyzr"   r&   s       r$   mapping_functionz5Homotopy.function_at_time_t.<locals>.mapping_function[   s0    GAq!8DMM!Q155666r%   )r)   r   r'   r    )r"   r&   r1   s   `` r$   function_at_time_tzHomotopy.function_at_time_tZ   s/    	7 	7 	7 	7 	7 	7 	7  r%   
submobjectstarting_submobjectalphar   c                j    |j         |_          |j        |                     |          fi | j         | S r+   )pointsapply_functionr3   r   )r"   r4   r5   r6   s       r$   interpolate_submobjectzHomotopy.interpolate_submobjecta   sN     06
!
!##E**	
 	
(	
 	
 	
 r%   )r   N)
r   r   r   r   r   r   r   r   r   r   )r&   r   r'   r   r4   r   r5   r   r6   r   r'   r   )__name__
__module____qualname____doc__r!   r3   r:   __classcell__r#   s   @r$   r   r      s}        * *` 7;? ? ? ? ? ? ?              r%   r   c                        e Zd Zd	 fdZ xZS )
r   r4   r   r5   r6   r   r'   r   c                    t          |t                    sJ t                                          |||           |                                 | S r+   )
isinstancer   r    r:   make_smooth)r"   r4   r5   r6   r#   s       r$   r:   z1SmoothedVectorizedHomotopy.interpolate_submobjectp   sO     *h/////&&z3FNNN   r%   r;   )r<   r=   r>   r:   r@   rA   s   @r$   r   r   o   s=        	 	 	 	 	 	 	 	 	 	r%   r   c                        e Zd Zd fdZ xZS )	r   complex_homotopy!Callable[[complex, float], float]r   r   r   r   c                L    d
fd} t                      j        ||fi | d	S )z)Complex Homotopy a function Cx[0, 1] to Cr.   r   r/   r0   r&   r'   tuple[float, float, float]c                V     t          | |          |          }|j        |j        |fS r+   )complexrealimag)r.   r/   r0   r&   crG   s        r$   r   z*ComplexHomotopy.__init__.<locals>.homotopy   s0     ! A22AFAFA&&r%   N)
r.   r   r/   r   r0   r   r&   r   r'   rJ   )r    r!   )r"   rG   r   r   r   r#   s    `   r$   r!   zComplexHomotopy.__init__}   sK    	' 	' 	' 	' 	' 	' 	755f55555r%   )rG   rH   r   r   r   r   )r<   r=   r>   r!   r@   rA   s   @r$   r   r   |   s=        6 6 6 6 6 6 6 6 6 6r%   r   c                  0     e Zd Zddefd fdZddZ xZS )r      Ffunction"Callable[[np.ndarray], np.ndarray]r   r   virtual_timer   suspend_mobject_updatingbool	rate_funcr   r   r   c                ^    || _         || _         t                      j        |f||d| d S )N)rU   rW   )rT   rR   r    r!   )r"   rR   r   rT   rU   rW   r   r#   s          r$   r!   zPhaseFlow.__init__   sV     ) 	
%=	
 	
 		
 	
 	
 	
 	
r%   r6   r'   Nonec                     t           d          rV j                             |                                j                  z
  z   j                             fd           | _        d S )N
last_alphac                :    |                      |           z  z   S r+   )rR   )r)   dtr"   s    r$   <lambda>z/PhaseFlow.interpolate_mobject.<locals>.<lambda>   s    !b4==;K;K6K2K r%   )hasattrrT   rW   r[   r   r9   )r"   r6   r]   s   ` @r$   interpolate_mobjectzPhaseFlow.interpolate_mobject   sv    4&& 	M"u%%t(G(GGB L''(K(K(K(K(KLLL!&r%   )rR   rS   r   r   rT   r   rU   rV   rW   r   r   r   r6   r   r'   rY   )r<   r=   r>   r   r!   r`   r@   rA   s   @r$   r   r      sa        
  )."(
 
 
 
 
 
 
$' ' ' ' ' ' ' 'r%   r   c                  0     e Zd ZdZ	 dd fdZddZ xZS )r   a  Make one mobject move along the path of another mobject.

    .. manim:: MoveAlongPathExample

        class MoveAlongPathExample(Scene):
            def construct(self):
                d1 = Dot().set_color(ORANGE)
                l1 = Line(LEFT, RIGHT)
                l2 = VMobject()
                self.add(d1, l1, l2)
                l2.add_updater(lambda x: x.become(Line(LEFT, d1.get_center()).set_color(ORANGE)))
                self.play(MoveAlongPath(d1, l1), rate_func=linear)
    Fr   r   pathr   rU   rV   r   r   c                N    || _          t                      j        |fd|i| d S )NrU   )rc   r    r!   )r"   r   rc   rU   r   r#   s        r$   r!   zMoveAlongPath.__init__   sI     		
 	
.F	
JP	
 	
 	
 	
 	
r%   r6   r   r'   rY   c                    | j                             |                     |                    }| j                            |           d S r+   )rc   point_from_proportionrW   r   move_to)r"   r6   points      r$   r`   z!MoveAlongPath.interpolate_mobject   s?    	//u0E0EFFU#####r%   )F)r   r   rc   r   rU   rV   r   r   ra   )r<   r=   r>   r?   r!   r`   r@   rA   s   @r$   r   r      se         $ */	

 

 

 

 

 

 

$ $ $ $ $ $ $ $r%   r   )r?   
__future__r   __all__collections.abcr	   typingr
   r   numpyr,   animation.animationr   utils.rate_functionsr   r   &manim.mobject.types.vectorized_mobjectr   manim.typingr   r   manim.utils.rate_functionsr   mobject.mobjectr   r   r   r   r   r   r2   r%   r$   <module>rt      s   % % " " " " " "   % $ $ $ $ $ % % % % % % % %     + + + + + + ) ) ) ) ) ) *??????55555555777777))))))M M M M My M M M`
 
 
 
 
 
 
 
6 6 6 6 6h 6 6 6*' ' ' ' '	 ' ' '8$ $ $ $ $I $ $ $ $ $r%   