
    lj$                        d Z ddlmZ ddgZddlmZmZ ddlZddl	m
Z
 ddlmZ dd	lmZ erdd
lmZ ddlmZ  G d de
e          Z G d de          ZdS )zDSimple mobjects that can be used for storing (and updating) a value.    )annotationsValueTrackerComplexValueTracker)TYPE_CHECKINGAnyN)Mobject)ConvertToOpenGL)straight_path)Self)PathFuncTypec                       e Zd ZdZd'd( fd	Zd)d
Zd*dZd+dZd,dZd-dZ	d.dZ
d/dZd+dZd/dZd+dZd/dZd+dZd/dZd+dZd-dZd.dZd/dZd+dZ e            fd0d&Z xZS )1r   a  A mobject that can be used for tracking (real-valued) parameters.
    Useful for animating parameter changes.

    Not meant to be displayed.  Instead the position encodes some
    number, often one which another animation or continual_animation
    uses for its update function, and by treating it as a mobject it can
    still be animated and manipulated just like anything else.

    This value changes continuously when animated using the :attr:`animate` syntax.

    Examples
    --------
    .. manim:: ValueTrackerExample

        class ValueTrackerExample(Scene):
            def construct(self):
                number_line = NumberLine()
                pointer = Vector(DOWN)
                label = MathTex("x").add_updater(lambda m: m.next_to(pointer, UP))

                tracker = ValueTracker(0)
                pointer.add_updater(
                    lambda m: m.next_to(
                                number_line.n2p(tracker.get_value()),
                                UP
                            )
                )
                self.add(number_line, pointer,label)
                tracker += 1.5
                self.wait(1)
                tracker -= 4
                self.wait(0.5)
                self.play(tracker.animate.set_value(5))
                self.wait(0.5)
                self.play(tracker.animate.set_value(3))
                self.play(tracker.animate.increment_value(-2))
                self.wait(0.5)

    .. note::

        You can also link ValueTrackers to updaters. In this case, you have to make sure that the
        ValueTracker is added to the scene by ``add``

    .. manim:: ValueTrackerExample

        class ValueTrackerExample(Scene):
            def construct(self):
                tracker = ValueTracker(0)
                label = Dot(radius=3).add_updater(lambda x : x.set_x(tracker.get_value()))
                self.add(label)
                self.add(tracker)
                tracker.add_updater(lambda mobject, dt: mobject.increment_value(dt))
                self.wait(2)

    r   valuefloatkwargsr   returnNonec                     t                      j        di | |                     t          j        d                     |                     |           d S )N)      points )super__init__setnpzeros	set_value)selfr   r   	__class__s      V/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/value_tracker.pyr   zValueTracker.__init__N   sV    ""6"""(()))u    c                     | j         d         }|S )z+Get the current value of this ValueTracker.r   r   r   r   r   s     r!   	get_valuezValueTracker.get_valueS   s    {4(r"   r   c                    || j         d<   | S )z,Sets a new scalar value to the ValueTracker.r$   r   r%   s     r!   r   zValueTracker.set_valueX   s    !Dr"   d_valuec                Z    |                      |                                 |z              | S )z5Increments (adds) a scalar value to the ValueTracker.r   r&   r   r(   s     r!   increment_valuezValueTracker.increment_value]   (    t~~'''1222r"   boolc                D    t          |                                           S )z@Return whether the value of this ValueTracker evaluates as true.)r.   r&   r   s    r!   __bool__zValueTracker.__bool__b   s    DNN$$%%%r"   float | Mobjectc                    t          |t                    rt          d          t          |                                 |z             S )zpReturn a new :class:`ValueTracker` whose value is the current tracker's value plus
        ``d_value``.
        JCannot increment ValueTracker by a Mobject. Please provide a scalar value.
isinstancer   
ValueErrorr   r&   r+   s     r!   __add__zValueTracker.__add__f   J     gw'' 	\   DNN,,w6777r"   c                x    t          |t                    rt          d          |                     |           | S )z>adds ``+=`` syntax to increment the value of the ValueTracker.r4   r6   r   r7   r,   r+   s     r!   __iadd__zValueTracker.__iadd__p   sD    gw'' 	\   	W%%%r"   c                J    t          |                                 |z            S )zReturn a new :class:`ValueTracker` whose value is the floor division of the current
        tracker's value by ``d_value``.
        r   r&   r+   s     r!   __floordiv__zValueTracker.__floordiv__y   !     DNN,,7888r"   c                Z    |                      |                                 |z             | S )z]Set the value of this ValueTracker to the floor division of the current value by ``d_value``.r*   r+   s     r!   __ifloordiv__zValueTracker.__ifloordiv__   (    t~~''72333r"   c                J    t          |                                 |z            S )zrReturn a new :class:`ValueTracker` whose value is the current tracker's value
        modulo ``d_value``.
        r>   r+   s     r!   __mod__zValueTracker.__mod__   !     DNN,,w6777r"   c                Z    |                      |                                 |z             | S )zKSet the value of this ValueTracker to the current value modulo ``d_value``.r*   r+   s     r!   __imod__zValueTracker.__imod__   r-   r"   c                J    t          |                                 |z            S )zyReturn a new :class:`ValueTracker` whose value is the current tracker's value multiplied by
        ``d_value``.
        r>   r+   s     r!   __mul__zValueTracker.__mul__   rF   r"   c                Z    |                      |                                 |z             | S )zWSet the value of this ValueTracker to the product of the current value and ``d_value``.r*   r+   s     r!   __imul__zValueTracker.__imul__   r-   r"   c                J    t          |                                 |z            S )zReturn a new :class:`ValueTracker` whose value is the current tracker's value raised to the
        power of ``d_value``.
        r>   r+   s     r!   __pow__zValueTracker.__pow__   r@   r"   c                Z    |                      |                                 |z             | S )z[Set the value of this ValueTracker to the current value raised to the power of ``d_value``.r*   r+   s     r!   __ipow__zValueTracker.__ipow__   rC   r"   c                    t          |t                    rt          d          t          |                                 |z
            S )zqReturn a new :class:`ValueTracker` whose value is the current tracker's value minus
        ``d_value``.
        JCannot decrement ValueTracker by a Mobject. Please provide a scalar value.r5   r+   s     r!   __sub__zValueTracker.__sub__   r9   r"   c                z    t          |t                    rt          d          |                     |            | S )z>Adds ``-=`` syntax to decrement the value of the ValueTracker.rR   r;   r+   s     r!   __isub__zValueTracker.__isub__   sF    gw'' 	\   	gX&&&r"   c                J    t          |                                 |z            S )zvReturn a new :class:`ValueTracker` whose value is the current tracker's value
        divided by ``d_value``.
        r>   r+   s     r!   __truediv__zValueTracker.__truediv__   rF   r"   c                Z    |                      |                                 |z             | S )zPSets the value of this ValueTracker to the current value divided by ``d_value``.r*   r+   s     r!   __itruediv__zValueTracker.__itruediv__   r-   r"   mobject1r   mobject2alpha	path_funcr   c                \    |                       ||j        |j        |                     | S )zKTurns ``self`` into an interpolation between ``mobject1`` and ``mobject2``.r   )r   r   )r   rZ   r[   r\   r]   s        r!   interpolatezValueTracker.interpolate   s/     			(/8?EJJKKKr"   )r   )r   r   r   r   r   r   )r   r   )r   r   r   r   )r(   r   r   r   )r   r.   )r(   r2   r   r   )r(   r2   r   r   )r(   r   r   r   )
rZ   r   r[   r   r\   r   r]   r   r   r   )__name__
__module____qualname____doc__r   r&   r   r,   r1   r8   r<   r?   rB   rE   rH   rJ   rL   rN   rP   rS   rU   rW   rY   r
   r_   __classcell__)r    s   @r!   r   r      s       6 6p      
   
   
   
& & & &8 8 8 8   9 9 9 9   
8 8 8 8   
8 8 8 8   
9 9 9 9   
8 8 8 8   8 8 8 8    #0-//	 	 	 	 	 	 	 	 	r"   )	metaclassc                  "    e Zd ZdZd
dZddZd	S )r   a  Tracks a complex-valued parameter.

    The value is internally stored as a points array [a, b, 0]. This can be accessed directly
    to represent the value geometrically, see the usage example.
    When the value is set through :attr:`animate`, the value will take a straight path from the
    source point to the destination point.

    Examples
    --------
    .. manim:: ComplexValueTrackerExample

        class ComplexValueTrackerExample(Scene):
            def construct(self):
                tracker = ComplexValueTracker(-2+1j)
                dot = Dot().add_updater(
                    lambda x: x.move_to(tracker.points)
                )

                self.add(NumberPlane(), dot)

                self.play(tracker.animate.set_value(3+2j))
                self.play(tracker.animate.set_value(tracker.get_value() * 1j))
                self.play(tracker.animate.set_value(tracker.get_value() - 2j))
                self.play(tracker.animate.set_value(tracker.get_value() / (-2 + 3j)))
    r   complexc                2    t          | j        dddf          S )zFGet the current value of this ComplexValueTracker as a complex number.r   N   )rg   r   r0   s    r!   r&   zComplexValueTracker.get_value   s    ArrE*++r"   r   complex | floatr   c                X    t          |          }|j        |j        f| j        dddf<   | S )z4Sets a new complex value to the ComplexValueTracker.r   Nri   )rg   realimagr   )r   r   zs      r!   r   zComplexValueTracker.set_value   s/    ENNfaf-ArrEr"   N)r   rg   )r   rj   r   r   )r`   ra   rb   rc   r&   r   r   r"   r!   r   r      sF         4, , , ,     r"   )rc   
__future__r   __all__typingr   r   numpyr   manim.mobject.mobjectr   )manim.mobject.opengl.opengl_compatibilityr	   manim.utils.pathsr
   r   manim.typingr   r   r   r   r"   r!   <module>rw      s   J J " " " " " "0
1 % % % % % % % %     ) ) ) ) ) ) E E E E E E + + + + + + *))))))w w w w w7o w w w wt# # # # #, # # # # #r"   