
    lj                        d Z ddlmZ ddgZddlmZ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 dd
lmZmZmZmZmZmZ ddlmZmZ  G d de          Z G d dee          ZdS )z6Animation of a mobject boundary and tracing of points.    )annotationsAnimatedBoundary
TracedPath)CallableSequence)AnySelf)Mobject)ConvertToOpenGL)VGroupVMobject)BLUE_BBLUE_DBLUE_E
GREY_BROWNWHITEParsableManimColor)RateFunctionsmoothc                  J     e Zd ZdZeeeegdddeefd fdZ	ddZ
d dZ xZS )!r   a  Boundary of a :class:`.VMobject` with animated color change.

    Examples
    --------
    .. manim:: AnimatedBoundaryExample

        class AnimatedBoundaryExample(Scene):
            def construct(self):
                text = Text("So shiny!")
                boundary = AnimatedBoundary(text, colors=[RED, GREEN, BLUE],
                                            cycle_rate=3)
                self.add(text, boundary)
                self.wait(2)

       g      ?Tvmobjectr   colorsSequence[ParsableManimColor]max_stroke_widthfloat
cycle_rateback_and_forthbooldraw_rate_funcr   fade_rate_funckwargsr   c                <     t                      j        di | | _        | _        | _        | _        | _        | _         _        fdt          d          D              _
          j         j
          d _                              fd           d S )Nc                b    g | ]+}                                                     d d           ,S )r   )stroke_widthfill_opacity)copy	set_style).0xr   s     S/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/animation/changing.py
<listcomp>z-AnimatedBoundary.__init__.<locals>.<listcomp><   sA      
  
  
JKHMMOO%%11%EE 
  
  
               c                .                         |          S )N)update_boundary_copies)mdtselfs     r+   <lambda>z+AnimatedBoundary.__init__.<locals>.<lambda>A   s    t'B'B2'F'F r-    )super__init__r   r   r   r   r    r!   r   rangeboundary_copiesadd
total_timeadd_updater)
r4   r   r   r   r   r   r    r!   r"   	__class__s
   ``       r+   r8   zAnimatedBoundary.__init__)   s     	""6""" 0$,,,  
  
  
  
OTUVxx 
  
  
 	$&''FFFFGGGGGr-   r3   returnNonec                P   | j         | j        z  }| j        \  }}| j        }| j        }| j        }t          |t          |          z            }|dz  }	|                     |	          }
| 	                    |	          }| j
        rt          |          dz  dk    rd|
z
  df}nd|
f} | j        ||g|R   |                    ||         |           |dk    r>|                     ||dd           |                    ||dz
           d|z
  |z             | xj         |z  c_         d S )N   r.         ?r/   )widthr   )colorrD   )r<   r   r:   r   r   r   intlenr    r!   r   full_family_become_partial
set_stroke)r4   r3   timegrowingfadingr   mswr   indexalpha
draw_alpha
fade_alphaboundss                r+   r1   z'AnimatedBoundary.update_boundary_copiesC   sR    0.#=D3v;;&''q((//
((//
 	'3t99q=A#5#5J&,FF:&F''CFCCCC6%=444199++FHaCCCF519$5a*nPS=STTT2r-   mob1mob2abr	   c                    |                                 }|                                 }t          ||d          D ]\  }}|                    |||           | S )NF)strict)family_members_with_pointszippointwise_become_partial)	r4   rS   rT   rU   rV   family1family2sm1sm2s	            r+   rH   z+AnimatedBoundary.full_family_become_partial_   sh     11331133GWU;;; 	4 	4HC((a3333r-   )r   r   r   r   r   r   r   r   r   r   r    r   r!   r   r"   r   )r3   r   r?   r@   )
rS   r   rT   r   rU   r   rV   r   r?   r	   )__name__
__module____qualname____doc__r   r   r   r   r   r8   r1   rH   __classcell__r>   s   @r+   r   r      s         & 17
/S"##'-'-H H H H H H H4   8       r-   c                  4     e Zd ZdZdedfd fdZddZ xZS )r   ak  Traces the path of a point returned by a function call.

    Parameters
    ----------
    traced_point_func
        The function to be traced.
    stroke_width
        The width of the trace.
    stroke_color
        The color of the trace.
    dissipating_time
        The time taken for the path to dissipate. Default set to ``None``
        which disables dissipation.

    Examples
    --------
    .. manim:: TracedPathExample

        class TracedPathExample(Scene):
            def construct(self):
                circ = Circle(color=RED).shift(4*LEFT)
                dot = Dot(color=RED).move_to(circ.get_start())
                rolling_circle = VGroup(circ, dot)
                trace = TracedPath(circ.get_start)
                rolling_circle.add_updater(lambda m: m.rotate(-0.3))
                self.add(trace, rolling_circle)
                self.play(rolling_circle.animate.shift(8*RIGHT), run_time=4, rate_func=linear)

    .. manim:: DissipatingPathExample

        class DissipatingPathExample(Scene):
            def construct(self):
                a = Dot(RIGHT * 2)
                b = TracedPath(a.get_center, dissipating_time=0.5, stroke_opacity=[0, 1])
                self.add(a, b)
                self.play(a.animate(path_arc=PI / 4).shift(LEFT * 2))
                self.play(a.animate(path_arc=-PI / 4).shift(LEFT * 2))
                self.wait()

    r.   Ntraced_point_funcr   r%   r   stroke_colorParsableManimColor | Nonedissipating_timefloat | Noner"   r   r?   r@   c                     t                      j        d||d| || _        || _        | j        rdnd | _        |                     | j                   d S )N)rh   r%   rC   r6   )r7   r8   rg   rj   rJ   r=   update_path)r4   rg   r%   rh   rj   r"   r>   s         r+   r8   zTracedPath.__init__   sj     	XlXXQWXXX!2 00:CCd	)*****r-   mobr
   r3   c                j   |                                  }|                                 s|                     |           |                     |           | j        rW| j        J | xj        |z  c_        | j        dz
  | j        k    r-| j        }|                     | j        |d                     d S d S d S )NrB   )	rg   
has_pointsstart_new_pathadd_line_torj   rJ   n_points_per_curve
set_pointspoints)r4   rn   r3   	new_pointnppccs        r+   rm   zTracedPath.update_path   s    **,,	   	+	***###  	59(((IIOIIy1}t444/EFF 344444	5 	5 54r-   )rg   r   r%   r   rh   ri   rj   rk   r"   r   r?   r@   )rn   r
   r3   r   r?   r@   )r`   ra   rb   rc   r   r8   rm   rd   re   s   @r+   r   r   i   sl        ' 'X  27)-+ + + + + + +
5 
5 
5 
5 
5 
5 
5 
5r-   )	metaclassN)rc   
__future__r   __all__collections.abcr   r   typingr   r	   manim.mobject.mobjectr
   )manim.mobject.opengl.opengl_compatibilityr   &manim.mobject.types.vectorized_mobjectr   r   manim.utils.colorr   r   r   r   r   r   manim.utils.rate_functionsr   r   r   r   r6   r-   r+   <module>r      sv   < < " " " " " "|
, . . . . . . . .         ) ) ) ) ) ) E E E E E E C C C C C C C C                < ; ; ; ; ; ; ;N N N N Nv N N NbB5 B5 B5 B5 B5_ B5 B5 B5 B5 B5 B5r-   