
    lj                       U d Z ddlmZ ddlmZ ddlmZ dgZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ dd	lmZ dd
lmZ ddlZddlmZ 	 ddlmZ dZ ej                      ej                    Zn# e$ r dZY nw xY w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,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAT ddlBmCZC ddlDmEZEmFZFmGZG ddlHmIZI ddlJmKZKmLZL ddlMmNZNmOZO dd lPmQZQ dd!lRmSZS dd"lTmUZU dd#lVmWZWmXZX dd$lYmZZZ e%r"dd%l[m\Z\ dd&l$m]Z]m^Z^ dd'l_m`Z` e3d(z  d)z  Zad*ebd+<   	 e G d, d(                      Zc G d- d)          Zd G d. d/e-          Ze G d0 d          ZfdS )1zBasic canvas for animations.    )annotations)flatten_iterable_parameters   )_AnimationBuilderSceneN)	dataclass)Path)Queue)DefaultSectionTypeTF)CallableIterableSequence)TYPE_CHECKINGAny)tqdm)DirModifiedEventFileModifiedEventFileSystemEventHandler)Observer)__version__)MethodWithArgs)Mobject)OpenGLPoint)configlogger)	AnimationWaitprepare_animation)Camera)*)CairoRenderer)OpenGLCameraOpenGLMobjectOpenGLRenderer)Object3D)opengl	space_ops)EndSceneEarlyExceptionRerunSceneException)extract_mobject_family_members)2restructure_list_to_exclude_certain_family_members)open_media_file)list_difference_updatelist_update)scene_classes_from_file)	FrameType)Self	TypeAlias)Point3DSceneInteractContinueSceneInteractRerunr2   SceneInteractActionc                  $    e Zd ZU dZdgZded<   dS )r4   a  Object which, when encountered in :meth:`.Scene.interact`, triggers
    the end of the scene interaction, continuing with the rest of the
    animations, if any. This object can be queued in :attr:`.Scene.queue`
    for later use in :meth:`.Scene.interact`.

    Attributes
    ----------
    sender : str
        The name of the entity which issued the end of the scene interaction,
        such as ``"gui"`` or ``"keyboard"``.
    senderstrN)__name__
__module____qualname____doc__	__slots____annotations__     L/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/scene/scene.pyr4   r4   V   s,         
 
 
IKKKKKrA   c                  "    e Zd ZdZddgZd
dZd	S )r5   ak  Object which, when encountered in :meth:`.Scene.interact`, triggers
    the rerun of the scene. This object can be queued in :attr:`.Scene.queue`
    for later use in :meth:`.Scene.interact`.

    Attributes
    ----------
    sender : str
        The name of the entity which issued the rerun of the scene, such as
        ``"gui"``, ``"keyboard"``, ``"play"`` or ``"file"``.
    kwargs : dict[str, Any]
        Additional keyword arguments when rerunning the scene. Currently,
        only ``"from_animation_number"`` is being used, which determines the
        animation from which to start rerunning the scene.
    r8   kwargsr9   r   returnNonec                "    || _         || _        d S N)r8   rD   )selfr8   rD   s      rB   __init__zSceneInteractRerun.__init__{   s    rA   N)r8   r9   rD   r   rE   rF   )r:   r;   r<   r=   r>   rJ   r@   rA   rB   r5   r5   i   s>          8$I     rA   c                  ,     e Zd ZdZd
 fdZdd	Z xZS )RerunSceneHandlerzEA class to handle rerunning a Scene after the input file is modified.queueQueue[SceneInteractAction]rE   rF   c                V    t                                                       || _        d S rH   )superrJ   rM   )rI   rM   	__class__s     rB   rJ   zRerunSceneHandler.__init__   s$    


rA   event$DirModifiedEvent | FileModifiedEventc                T    | j                             t          d                     d S )NfilerM   putr5   )rI   rR   s     rB   on_modifiedzRerunSceneHandler.on_modified   s%    
)&1122222rA   )rM   rN   rE   rF   )rR   rS   rE   rF   )r:   r;   r<   r=   rJ   rX   __classcell__)rQ   s   @rB   rL   rL      sW        OO     3 3 3 3 3 3 3 3rA   rL   c                     e Zd ZdZdedddfddZedd            Zedd            ZddZ	dddZ
ddZddZddZdej        dfdd Zdd!Zdd$Zdd&Zdd'Zdd(Zdd)Zdd+Zdd,Zdd0Zdd3Zdd5Zdd8Zdd;Zdd<Z	 	 dddBZddDZ ddEZ!ddGZ"ddHZ#ddIZ$ddJZ%ddKZ&ddLZ'ddNZ(ddQZ)ddVZ*ddYZ+	 	 ddd^Z,e-	 dddb            Z.ddcZ/dddddeddkZ0e1ddfddpZ2e1fddqZ3	 ddduZ4ddxZ5ddyZ6ddzZ7ddd|Z8dd}Z9dd~Z:ddZ;ddZ<dddZ=ddZ>	 dddZ?	 	 dddZ@ddZAddZBddZCddZDddZEddZFddZGddZHddZIdS )r   a  A Scene is the canvas of your animation.

    The primary role of :class:`Scene` is to provide the user with tools to manage
    mobjects and animations.  Generally speaking, a manim script consists of a class
    that derives from :class:`Scene` whose :meth:`Scene.construct` method is overridden
    by the user's code.

    Mobjects are displayed on screen by calling :meth:`Scene.add` and removed from
    screen by calling :meth:`Scene.remove`.  All mobjects currently on screen are kept
    in :attr:`Scene.mobjects`.  Animations are played by calling :meth:`Scene.play`.

    A :class:`Scene` is rendered internally by calling :meth:`Scene.render`.  This in
    turn calls :meth:`Scene.setup`, :meth:`Scene.construct`, and
    :meth:`Scene.tear_down`, in that order.

    It is not recommended to override the ``__init__`` method in user Scenes.  For code
    that should be ran before a Scene is rendered, use :meth:`Scene.setup` instead.

    Examples
    --------
    Override the :meth:`Scene.construct` method with your code.

    .. code-block:: python

        class MyScene(Scene):
            def construct(self):
                self.play(Write(Text("Hello World!")))

    NFrenderer%CairoRenderer | OpenGLRenderer | Nonecamera_classtype[Camera]always_update_mobjectsboolrandom_seed
int | Noneskip_animationsrE   rF   c                2   || _         || _        ||nt          j        | _        || _        d | _        d | _        g | _        g | _	        d | _
        d| _        d| _        t                      | _        d| _        g | _        t"          | _        g | _        t(          | _        g | _        i | _        g | _        d| _        t          j        t4          j        k    r6t9                      | _        t9                      | _        |t?                      }|!tA          | j         | j                  | _        n|| _        | j        !                    |            g | _"        g | _#        tI          j        | j                   tJ          j$                            | j                   d S )Ng        F)r]   rc   )&r]   r_   r   seedra   rc   
animationsstop_conditionmoving_mobjectsstatic_mobjectstime_progressiondurationlast_tr
   rM   skip_animation_previewmeshesORIGINcamera_targetwidgetsdearpygui_importedupdaterskey_to_function_mapmouse_press_callbacksinteractive_moder[   RendererTypeOPENGLr   mouse_pointmouse_drag_pointr$   r!   
init_scenemobjectsforeground_mobjectsrandomnp)rI   r[   r]   r_   ra   rc   s         rB   rJ   zScene.__init__   sw    )&<#*5*A;;v{.269=.0.048"16
&+#&(#-/"479BD ?A" %?l111*}}D$/MMD!)++<I ". $ 4	= = =DMM %DM  &&&')24 D$%%%
	t'(((((rA   Camera | OpenGLCamerac                    | j         j        S rH   )r[   camerarI   s    rB   r   zScene.camera   s    }##rA   floatc                    | j         j        S )z&The time since the start of the scene.)r[   timer   s    rB   r   z
Scene.time   s     }!!rA   clone_from_iddict[int, Any]c           	         | j         }|                    |          }||t          |           <   | j                                        D ]E\  }}|dv r
|dk    rt          |||           t          ||t          j        ||                     F|S )N)r[   rj   r]   )rQ   __new__id__dict__itemssetattrcopydeepcopy)rI   r   clsresultkvs         rB   __deepcopy__zScene.__deepcopy__   s    nS!!"(bhhM'')) 	@ 	@DAq444N""1%%%FAt}Q>>????rA   previewc                   |                                   	 |                                  nP# t          $ r Y nDt          $ r8  | j        | j          | j                                         d| j        _        Y dS w xY w| 	                                 | j        
                    |            | j        j        st          d         dk    st          d         r2t          j        dt          |            d| j        j         d           |r
dt          d	<   t          d	         st          d
         rt          | j        j                   dS )z
        Renders this Scene.

        Parameters
        ---------
        preview
            If true, opens scene in a file viewer.
        r   Tformatpngsave_last_framez	Rendered z
Played z animationsr   show_in_file_browserF)setup	constructr(   r)   remover|   r[   clear_screen	num_plays	tear_downscene_finishedr   r   infor9   r,   file_writer)rI   r   s     rB   renderzScene.render   sc    	

		NN% 	 	 	D" 	 	 	DK''M&&(((&'DM#44	 	$$T*** M#	h5(('( ) KTCIITT0GTTT  
  	% $F9) 	7'= > 	7DM5666us   + 
A8=A87A8c                    dS )z
        This is meant to be implemented by any scenes which
        are commonly subclassed, and have some common setup
        involved before the construct method is called.
        Nr@   r   s    rB   r   zScene.setup#  	     	rA   c                    dS )z
        This is meant to be implemented by any scenes which
        are commonly subclassed, and have some common method
        to be invoked before the scene ends.
        Nr@   r   s    rB   r   zScene.tear_down+  r   rA   c                    dS )a  Add content to the Scene.

        From within :meth:`Scene.construct`, display mobjects on screen by calling
        :meth:`Scene.add` and remove them from screen by calling :meth:`Scene.remove`.
        All mobjects currently on screen are kept in :attr:`Scene.mobjects`.  Play
        animations by calling :meth:`Scene.play`.

        Notes
        -----
        Initialization code should go in :meth:`Scene.setup`.  Termination code should
        go in :meth:`Scene.tear_down`.

        Examples
        --------
        A typical manim script includes a class derived from :class:`Scene` with an
        overridden :meth:`Scene.construct` method:

        .. code-block:: python

            class MyScene(Scene):
                def construct(self):
                    self.play(Write(Text("Hello World!")))

        See Also
        --------
        :meth:`Scene.setup`
        :meth:`Scene.render`
        :meth:`Scene.tear_down`

        Nr@   r   s    rB   r   zScene.construct3  s	    > 	rA   unnamednamer9   section_typec                H    | j         j                            |||           dS )a  Create separation here; the last section gets finished and a new one gets created.
        ``skip_animations`` skips the rendering of all animations in this section.
        Refer to :doc:`the documentation</tutorials/output_and_config>` on how to use sections.
        N)r[   r   next_section)rI   r   r   rc   s       rB   r   zScene.next_sectionT  s'     	!..t\?SSSSSrA   c                    | j         j        S rH   )rQ   r:   r   s    rB   __str__zScene.__str__`  s    ~&&rA   keys	list[Any]c                       fd|D             S )a3  
        Gets attributes of a scene given the attribute's identifier/name.

        Parameters
        ----------
        *keys
            Name(s) of the argument(s) to return the attribute of.

        Returns
        -------
        list
            List of attributes of the passed identifiers.
        c                0    g | ]}t          |          S r@   getattr).0keyrI   s     rB   
<listcomp>z#Scene.get_attrs.<locals>.<listcomp>q  s#    333sc""333rA   r@   )rI   r   s   ` rB   	get_attrszScene.get_attrsc  s     4333d3333rA   dtc                D    | j         D ]}|                    |           dS )z
        Begins updating all mobjects in the Scene.

        Parameters
        ----------
        dt
            Change in time between updates. Defaults (mostly) to 1/frames_per_second
        N)r|   update)rI   r   mobjs      rB   update_mobjectszScene.update_mobjectss  s0     M 	 	DKKOOOO	 	rA   c                r    | j         D ].}|                                D ]}|                    |           /d S rH   )rn   
get_familyr   )rI   r   objmeshs       rB   update_mesheszScene.update_meshes  sL    ; 	  	 C((    B 	  	 rA   c                0    | j         D ]} ||           dS )a  Run all scene updater functions.

        Among all types of update functions (mobject updaters, mesh updaters,
        scene updaters), scene update functions are called last.

        Parameters
        ----------
        dt
            Scene time since last update.

        See Also
        --------
        :meth:`.Scene.add_updater`
        :meth:`.Scene.remove_updater`
        Nrs   )rI   r   funcs      rB   update_selfzScene.update_self  s.      M 	 	DDHHHH	 	rA   c                   | j         J | j         d         }t          |t                    sJ |j        J| j        p:| j        p3|j        dup*t          d |                                 D                       }| |_        |j         S )a  
        Returns True if the mobjects of this scene should be updated.

        In particular, this checks whether

        - the :attr:`always_update_mobjects` attribute of :class:`.Scene`
          is set to ``True``,
        - the :class:`.Scene` itself has time-based updaters attached,
        - any mobject in this :class:`.Scene` has time-based updaters attached.

        This is only called when a single Wait animation is played.
        Nr   c              3  >   K   | ]}|                                 V  d S rH   )has_time_based_updater)r   mobs     rB   	<genexpr>z/Scene.should_update_mobjects.<locals>.<genexpr>  sB         ..00     rA   )	rf   
isinstancer   is_static_waitr_   rs   rg   anyget_mobject_family_members)rI   wait_animationshould_updates      rB   should_update_mobjectszScene.should_update_mobjects  s     ***+.$/////(0+ =!0<   #>>@@    	  1>,=N)!000rA   list[Mobject]c                v    d | j         D             dfd}t          t          || j                             S )z
        Returns all mobjects which are not submobjects.

        Returns
        -------
        list
            List of top level mobjects.
        c                6    g | ]}|                                 S r@   )r   )r   ms     rB   r   z0Scene.get_top_level_mobjects.<locals>.<listcomp>  s     :::qALLNN:::rA   mobjectr   rE   r`   c                H     t           fdD                       }|dk    S )Nc              3      K   | ]}|v V  	d S rH   r@   )r   familyr   s     rB   r   zEScene.get_top_level_mobjects.<locals>.is_top_level.<locals>.<genexpr>  s(      JJv6 1JJJJJJrA      )sum)r   num_familiesfamiliess   ` rB   is_top_levelz2Scene.get_top_level_mobjects.<locals>.is_top_level  s1    JJJJJJJJJL1$$rA   )r   r   rE   r`   )r|   listfilter)rI   r   r   s     @rB   get_top_level_mobjectszScene.get_top_level_mobjects  sT     ;:DM:::	% 	% 	% 	% 	% 	% F<77888rA   c                "   t           j        t          j        k    r5g }| j        D ])}|                    |                                           *|S t           j        t          j        k    sJ t          | j        | j        j	        j
                  S )aW  
        Returns list of family-members of all mobjects in scene.
        If a Circle() and a VGroup(Rectangle(),Triangle()) were added,
        it returns not only the Circle(), Rectangle() and Triangle(), but
        also the VGroup() object.

        Returns
        -------
        list
            List of mobject family members.
        use_z_index)r   r[   rw   rx   r|   extendr   CAIROr*   r   r   )rI   family_membersr   s      rB   r   z Scene.get_mobject_family_members  s     ?l111N} 8 8%%cnn&6&67777!!?l&888881 M0<   rA   r|   Mobject | OpenGLMobjectr1   c                ,   t           j        t          j        k    r~g }g }|D ]B}t	          |t
                    r|                    |           -|                    |           C | j        |  | xj        |z  c_         | j        |  | xj	        |z  c_	        n{t           j        t          j
        k    sJ g || j        }|                     |           | xj        |z  c_        | j        r'|                     |d           | xj        |z  c_        | S )a9  
        Mobjects will be displayed, from background to
        foreground in the order with which they are added.

        Parameters
        ---------
        *mobjects
            Mobjects to add.

        Returns
        -------
        Scene
            The same scene after adding the Mobjects in.

        )	to_removerh   )r   mobject_list_name)r   r[   rw   rx   r   r%   appendr   r|   rn   r   r}   restructure_mobjectsrh   )rI   r|   new_mobjects
new_meshesmobject_or_meshnew_and_foreground_mobjectss         rB   addz	Scene.add  sT     ?l111L)+J#+ 9 9ox88 9%%o6666 ''8888DK&&MM\)MMDK$$KK:%KKK?l&88888::):' %%0K%LLLMM88MM# D))9&7 *    $$(CC$$rA   rf   list[Animation]c                    |                                  }|D ]P}|                                r|j        }|0||vr,|                     |           ||                                z  }Qd S rH   )r   is_introducerr   r   r   )rI   rf   curr_mobjects	animationr   s        rB   add_mobjects_from_animationsz"Scene.add_mobjects_from_animations  s    7799# 	2 	2I&&((  #C3m#;#;!1!11	2 	2rA   r   c                   t           j        t          j        k    rg }t	                      |D ]B}t          |t                    r                    |           -|                    |           Ct          | j
        |          | _
        d	fd}t          t          || j                            | _        | S t           j        t          j        k    sJ dD ]}|                     ||d           | S )
a  
        Removes mobjects in the passed list of mobjects
        from the scene and the foreground, by removing them
        from "mobjects" and "foreground_mobjects"

        Parameters
        ----------
        *mobjects
            The mobjects to remove.
        r   r%   rE   r`   c                &    | t                    vS rH   set)r   meshes_to_removes    rB   lambda_functionz%Scene.remove.<locals>.lambda_function0  s    3'7#8#888rA   r|   r}   FN)r   r%   rE   r`   )r   r[   rw   rx   r   r   r%   r   r   r+   r|   r   r   rn   r   r   )rI   r|   mobjects_to_remover   r  	list_namer   s         @rB   r   zScene.remove  s    ?l111!#.1ee#+ ? ?ox88 ?$((9999&--o>>>>N" DM
9 9 9 9 9 9 44 DK K?l&88888> F F	))(IuEEEEKrA   old_mobjectnew_mobjectc                    ||t          d          dfd
 | j        ||          p | j        ||          }|st          d| d          dS )a  Replace one mobject in the scene with another, preserving draw order.

        If ``old_mobject`` is a submobject of some other Mobject (e.g. a
        :class:`.Group`), the new_mobject will replace it inside the group,
        without otherwise changing the parent mobject.

        Parameters
        ----------
        old_mobject
            The mobject to be replaced. Must be present in the scene.
        new_mobject
            A mobject which must not already be in the scene.

        Nz!Specified mobjects cannot be None	mobj_listr   old_mr   new_mrE   r`   c                6   || v rE||u r,t          j        dt          |          j         d           dS |                     |           t          dt          |                     D ]}| |         |k    r|| |<    dS | D ]} |j        ||          r dS dS )NzAttempted to replace z with itself in Scene.mobjects.Tr   F)r   warningtyper:   r   rangelensubmobjects)r  r	  r
  ir   replace_in_lists        rB   r  z&Scene.replace.<locals>.replace_in_listO  s     	!!E>> N9U0D 9 9 9    4  ''' 1c)nn--    Q<5((#(IaL44 )
 !    "?3?E5AA  44 
 5rA   zCould not find z	 in scene)r  r   r	  r   r
  r   rE   r`   )
ValueErrorr|   r}   )rI   r  r  replacedr  s       @rB   replacezScene.replace=  s     +"5@AAA	 	 	 	 	 	F #?M;
 
 Q_T5{KPP 	  	GE{EEEFFF	G 	GrA   r   Callable[[float], None]c                :    | j                             |           dS )a  Add an update function to the scene.

        The scene updater functions are run every frame,
        and they are the last type of updaters to run.

        .. WARNING::

            When using the Cairo renderer, scene updaters that
            modify mobjects are not detected in the same way
            that mobject updaters are. To be more concrete,
            a mobject only modified via a scene updater will
            not necessarily be added to the list of *moving
            mobjects* and thus might not be updated every frame.

            TL;DR: Use mobject updaters to update mobjects.

        Parameters
        ----------
        func
            The updater function. It takes a float, which is the
            time difference since the last update (usually equal
            to the frame rate).

        See also
        --------
        :meth:`.Scene.remove_updater`
        :meth:`.Scene.update_self`
        N)rs   r   rI   r   s     rB   add_updaterzScene.add_updatery  s     : 	T"""""rA   c                8    fd| j         D             | _         dS )zRemove an update function from the scene.

        Parameters
        ----------
        func
            The updater function to be removed.

        See also
        --------
        :meth:`.Scene.add_updater`
        :meth:`.Scene.update_self`
        c                    g | ]}|u|	S r@   r@   )r   fr   s     rB   r   z(Scene.remove_updater.<locals>.<listcomp>  s    CCCqQd]]]]]rA   Nr   r  s    `rB   remove_updaterzScene.remove_updater  s'     DCCCDMCCCrA   Tr   Sequence[Mobject]r   extract_familiesc                    |r t          || j        j        j                  }t	          | |          }|                     ||          }t          | ||           | S )a  
        tl:wr
            If your scene has a Group(), and you removed a mobject from the Group,
            this dissolves the group and puts the rest of the mobjects directly
            in self.mobjects or self.foreground_mobjects.

        In cases where the scene contains a group, e.g. Group(m1, m2, m3), but one
        of its submobjects is removed, e.g. scene.remove(m1), the list of mobjects
        will be edited to contain other submobjects, but not m1, e.g. it will now
        insert m2 and m3 to where the group once was.

        Parameters
        ----------
        to_remove
            The Mobject to remove.

        mobject_list_name
            The list of mobjects ("mobjects", "foreground_mobjects" etc) to remove from.

        extract_families
            Whether the mobject's families should be recursively extracted.

        Returns
        -------
        Scene
            The Scene mobject with restructured Mobjects.
        r   )r*   r[   r   r   r   get_restructured_mobject_listr   )rI   r   r   r  _listnew_lists         rB   r   zScene.restructure_mobjects  sn    B  	6 M0<  I /0055eYGG'222rA   Iterable[Mobject]c                N    g dfd |t          |                     S )	a  
        Given a list of mobjects and a list of mobjects to be removed, this
        filters out the removable mobjects from the list of mobjects.

        Parameters
        ----------

        mobjects
            The Mobjects to check.

        to_remove
            The list of mobjects to remove.

        Returns
        -------
        list
            The list of mobjects with the mobjects to remove removed.
        list_to_examiner$  set_to_removeset[Mobject]rE   rF   c                    | D ]W}||v r|                     |                                          }|r |j        |           B                    |           Xd S rH   )intersectionr   r  r   )r&  r'  r   	intersectadd_safe_mobjects_from_listr   s       rB   r,  zHScene.get_restructured_mobject_list.<locals>.add_safe_mobjects_from_list  s     ' - --'')66s~~7G7GHH	 -//KKKK '',,,,- -rA   )r&  r$  r'  r(  rE   rF   r   )rI   r|   r   r,  r   s      @@rB   r!  z#Scene.get_restructured_mobject_list  sO    * ')
	- 
	- 
	- 
	- 
	- 
	- 
	- 	$#Hc)nn===rA   c                N    t          | j        |          | _         | j        |  | S )aM  
        Adds mobjects to the foreground, and internally to the list
        foreground_mobjects, and mobjects.

        Parameters
        ----------
        *mobjects
            The Mobjects to add to the foreground.

        Returns
        ------
        Scene
            The Scene, with the foreground mobjects added.
        )r.   r}   r   rI   r|   s     rB   add_foreground_mobjectszScene.add_foreground_mobjects  s-     $/t/G#R#R (rA   r   c                ,    |                      |          S )aQ  
        Adds a single mobject to the foreground, and internally to the list
        foreground_mobjects, and mobjects.

        Parameters
        ----------
        mobject
            The Mobject to add to the foreground.

        Returns
        ------
        Scene
            The Scene, with the foreground mobject added.
        )r/  rI   r   s     rB   add_foreground_mobjectzScene.add_foreground_mobject  s     ++G444rA   c                2    |                      |d           | S )aP  
        Removes mobjects from the foreground, and internally from the list
        foreground_mobjects.

        Parameters
        ----------
        *to_remove
            The mobject(s) to remove from the foreground.

        Returns
        ------
        Scene
            The Scene, with the foreground mobjects removed.
        r}   )r   )rI   r   s     rB   remove_foreground_mobjectsz Scene.remove_foreground_mobjects  s      	!!)-BCCCrA   c                ,    |                      |          S )aQ  
        Removes a single mobject from the foreground, and internally from the list
        foreground_mobjects.

        Parameters
        ----------
        mobject
            The mobject to remove from the foreground.

        Returns
        ------
        Scene
            The Scene, with the foreground mobject removed.
        )r4  r1  s     rB   remove_foreground_mobjectzScene.remove_foreground_mobject/  s     ..w777rA   c                     | j         |  | S )ak  
        Adds the passed mobjects to the scene again,
        pushing them to he front of the scene.

        Parameters
        ----------
        *mobjects
            The mobject(s) to bring to the front of the scene.

        Returns
        ------
        Scene
            The Scene, with the mobjects brought to the front
            of the scene.
        )r   r.  s     rB   bring_to_frontzScene.bring_to_front@  s      	(rA   c                R     | j         |  t          |          | j        z   | _        | S )a^  
        Removes the mobject from the scene and
        adds them to the back of the scene.

        Parameters
        ----------
        *mobjects
            The mobject(s) to push to the back of the scene.

        Returns
        ------
        Scene
            The Scene, with the mobjects pushed to the back
            of the scene.
        )r   r   r|   r.  s     rB   bring_to_backzScene.bring_to_backS  s,      	XX6rA   c                "    g | _         g | _        | S )a!  
        Removes all mobjects present in self.mobjects
        and self.foreground_mobjects from the scene.

        Returns
        ------
        Scene
            The Scene, with all of its mobjects in
            self.mobjects and self.foreground_mobjects
            removed.
        r  r   s    rB   clearzScene.clearg  s     #% rA   r   c                $   ddl m d
fd |          }|                                 }t          |          D ]Q\  }}||v t	          |                                          dk    || j        v g}t          |          r||d	         c S Rg S )a=  
        Gets all moving mobjects in the passed animation(s).

        Parameters
        ----------
        *animations
            The animations to check for moving mobjects.

        Returns
        ------
        list
            The list of mobjects that could be moving in
            the Animation(s)
        r   )AnimationGroupnested_animationsIterable[Animation]rE   list[Mobject | OpenGLMobject]c                    g }| D ]b}t          |          r$|                     |j                             6|                    |j                                                   c|S rH   )r   r   rf   r   r   )r?  animation_mobjectsanimr>  _collect_animation_mobjectss      rB   rE  z>Scene.get_moving_mobjects.<locals>._collect_animation_mobjects  s     AC) I IdN33 I&--33DODD    '--dl.E.E.G.GHHHH%%rA   r   N)r?  r@  rE   rA  )animation.compositionr>  r   	enumerater  get_family_updatersr}   r   )	rI   rf   rC  r|   r  r   update_possibilitiesr>  rE  s	          @@rB   get_moving_mobjectszScene.get_moving_mobjectsw  s    ( 	;:::::	& 	& 	& 	& 	& 	& 	& 98DD2244)) 	$ 	$FAs))C++--..2t//$ 
 '(( $|###$	rA   r@  #tuple[list[Mobject], list[Mobject]]c                    t          | j        | j                  }t          || j        j        j        d          } | j        | }t          || j        j        j                  }t          ||          }||fS )NT)r   only_those_with_pointsr   )	r.   r|   r}   r*   r[   r   r   rJ  r-   )rI   rf   all_mobjectsall_mobject_familiesrh   all_moving_mobject_familiesri   s          rB   get_moving_and_static_mobjectsz$Scene.get_moving_and_static_mobjects  s     #4=$2JKK=,8#' 
  
  

 3$2J?&D,8'
 '
 '
# 1 '
 
 +O;;rA   args'Animation | Mobject | _AnimationBuilderrD   r   c                l   g }t          |          }|D ]o}	 |                    t          |                     &# t          $ r=}t	          j        |          rt          d          |t          d| d          |d}~ww xY w|D ]-}|                                D ]\  }}	t          |||	           .|S )a  
        Creates _MethodAnimations from any _AnimationBuilders and updates animation
        kwargs with kwargs passed to play().

        Parameters
        ----------
        *args
            Animations to be played.
        **kwargs
            Configuration for the call to play().

        Returns
        -------
        Tuple[:class:`Animation`]
            Animations to be played.
        zZPassing Mobject methods to Scene.play is no longer supported. Use Mobject.animate instead.zUnexpected argument z passed to Scene.play().N)r   r   r   	TypeErrorinspectismethodr   r   )
rI   rR  rD   rf   	arg_animsarger   r   r   s
             rB   compile_animationszScene.compile_animations  s   * 
/55	 	 	C!!"3C"8"89999 	 	 	#C(( #C  
 $LsLLL 	 $ 	) 	)I ) )1	1a(((() s   ":
B8A<<Brk   tqdm[float]c           
        t          |          dk    rpt          |d         t                    rU|d         j        }|"|                     |d|j         dd          }n|                     |d| j        j                   }nb|                     |d	                    d
| j        j         dt          |d                   t          |          dk    rdnd	g                    }|S )aJ  
        You will hardly use this when making your own animations.
        This method is for Manim's internal use.

        Uses :func:`~.get_time_progression` to obtain a
        CommandLine ProgressBar whose ``fill_time`` is
        dependent on the qualities of the passed Animation,

        Parameters
        ----------
        animations
            The list of animations to get
            the time progression for.

        duration
            duration of wait time

        Returns
        -------
        time_progression
            The CommandLine Progress Bar.
        r   r   NzWaiting for T)n_iterationsoverride_skip_animationszWaiting  z
Animation z: z, etc.)
r  r   r   rg   get_time_progressionr:   r[   r   joinr9   )rI   rf   rk   rg   rj   s        rB   _get_animation_time_progressionz%Scene._get_animation_time_progression  s   2 z??aJz!}d$C$C']9N)#'#<#<<>#:<<!#-1	 $= $ $   $(#<#<8t}688$ $  
  $88@T]%<@@@JqM**%(__q%8%8b 	  	   rA   run_timedescriptionr_  r`  c           	        | j         j        r|s|g}n&dt          d         z  }t          j        d||          }t          |||t          d         dk    t          j                    dk    rdndt          d         d	k    
          }|S )a  
        You will hardly use this when making your own animations.
        This method is for Manim's internal use.

        Returns a CommandLine ProgressBar whose ``fill_time``
        is dependent on the ``run_time`` of an animation,
        the iterations to perform in that animation
        and a bool saying whether or not to consider
        the skipped animations.

        Parameters
        ----------
        run_time
            The ``run_time`` of the animation.

        n_iterations
            The number of iterations in the animation.

        override_skip_animations
            Whether or not to show skipped animations in the progress bar.

        Returns
        -------
        time_progression
            The CommandLine Progress Bar.
        r   
frame_rater   progress_barleaveWindowsTNnone)desctotalrj  asciidisable)r[   rc   r   r   aranger   platformsystem)rI   re  rf  r_  r`  timessteprj   s           rB   rb  zScene.get_time_progression  s    B =( 	11I 	1&.ZEEvl++DIa400E(G3"/++y88$$d>*f4
 
 
  rA   methodCallable[[Any], Any]parameter_namec                    | j          d|j          d}|dk    rt          | d| d|dd| d          t          j        }d	|z  }||k     r,t	          j        d
| d| d|dd|dd| d|dd           |}|S )N.z()r   z has a z of gz- <= 0 seconds which Manim cannot render. The z must be a positive number.r   zThe original z, z5 seconds, is too short for the current frame rate of z+ FPS. Rendering with the shortest possible z seconds instead.)r:   r  r   rh  r   r  )r   re  rv  rx  method_namefpsseconds_per_frames          rB   validate_run_timezScene.validate_run_timeK  s.    ;;;;;q== C C~ C CHC C%C C C   G'''NN N NK N NLN NMN N "N N (9MN N N   )HrA   c                p    t          d |D                       }|                     || j        d          }|S )aT  
        Gets the total run time for a list of animations.

        Parameters
        ----------
        animations
            A list of the animations whose total
            ``run_time`` is to be calculated.

        Returns
        -------
        float
            The total ``run_time`` of all of the animations in the list.
        c              3  $   K   | ]}|j         V  d S rH   re  )r   r   s     rB   r   z%Scene.get_run_time.<locals>.<genexpr>w  s%      FFiy)FFFFFFrA   ztotal run_time)maxr  play)rI   rf   re  s      rB   get_run_timezScene.get_run_timeh  s?     FF:FFFFF))(DI?OPPrA   r   
subcaptionsubcaption_durationsubcaption_offsetr  
str | Noner  float | Noner  c                  | j         rut          j        t          j        k    r[t          j                    j        dk    r?|                    |||d           | j	        
                    t          di |           dS | j        } | j        j        | g|R i | | j        |z
  }|r"||}|                     ||| |z              dS dS )a~  Plays an animation in this scene.

        Parameters
        ----------

        args
            Animations to be played.
        subcaption
            The content of the external subcaption that should
            be added during the animation.
        subcaption_duration
            The duration for which the specified subcaption is
            added. If ``None`` (the default), the run time of the
            animation is taken.
        subcaption_offset
            An offset (in seconds) for the start time of the
            added subcaption.
        kwargs
            All other keywords are passed to the renderer.

        
MainThreadr  r  N)contentrk   offset)r  )rv   r   r[   rw   rx   	threadingcurrent_threadr   r   rM   rW   r5   r   r  add_subcaption)rI   r  r  r  rR  rD   
start_timere  s           rB   r  z
Scene.play{  s   > !	<#666(**/<?? MM",+>):    JNN-????@@@FY
41$111&1119z) 	"*&.#
 ", y#44       	 	rA   rg   Callable[[], bool] | Nonefrozen_framebool | Nonec                    |                      || j        d          }|                     t          |||                     dS )aO  Plays a "no operation" animation.

        Parameters
        ----------
        duration
            The run time of the animation.
        stop_condition
            A function without positional arguments that is evaluated every time
            a frame is rendered. The animation only stops when the return value
            of the function is truthy, or when the time specified in ``duration``
            passes.
        frozen_frame
            If True, updater functions are not evaluated, and the animation outputs
            a frozen frame. If False, updater functions are called and frames
            are rendered as usual. If None (the default), the scene tries to
            determine whether or not the frame is frozen on its own.

        See also
        --------
        :class:`.Wait`, :meth:`.should_mobjects_update`
        rk   )re  rg   r  N)r  waitr  r   )rI   rk   rg   r  s       rB   r  z
Scene.wait  sX    6 ))(DIzJJ		!-)  	
 	
 	
 	
 	
rA   c                l    |                      || j        d          }|                     |d           dS )a=  Pauses the scene (i.e., displays a frozen frame).

        This is an alias for :meth:`.wait` with ``frozen_frame``
        set to ``True``.

        Parameters
        ----------
        duration
            The duration of the pause.

        See also
        --------
        :meth:`.wait`, :class:`.Wait`
        rk   T)rk   r  N)r  pauser  )rI   rk   s     rB   r  zScene.pause  s9     ))(DJ
KK		8$	77777rA   <   Callable[[], bool]max_timec                l    |                      || j        d          }|                     ||           dS )a=  Wait until a condition is satisfied, up to a given maximum duration.

        Parameters
        ----------
        stop_condition
            A function with no arguments that determines whether or not the
            scene should keep waiting.
        max_time
            The maximum wait time in seconds.
        r  )rg   N)r  
wait_untilr  )rI   rg   r  s      rB   r  zScene.wait_until  s9     ))(DOZPP		(>	:::::rA   play_kwargsSelf | Nonec                4   t          |          dk    rt          d           | j        |i || _        |                     | j                   d| _        d| _        g | _        g | _        | 	                    | j                  | _
        t          | j                  dk    rvt          | j        d         t                    rV|                                 r.|                     d           | j        d         j        | _        nd| j        d         _        dS | S )a5  Given a list of animations, compile the corresponding
        static and moving mobjects, and gather the animation durations.

        This also begins the animations.

        Parameters
        ----------
        animations
            Animation or mobject with mobject method and params
        play_kwargs
            Named parameters affecting what was passed in ``animations``,
            e.g. ``run_time``, ``lag_ratio`` and so on.

        Returns
        -------
        self, None
            None if there is nothing to play, or self otherwise.
        r   z$Called Scene.play with no animationsNr   )r   T)r  r  r[  rf   r   rl   rg   rh   ri   r  rk   r   r   r   r   r   )rI   rf   r  s      rB   compile_animation_datazScene.compile_animation_data  s   2 z??aCDDD1$1:MMM))$/:::"!!))$/::t1$$DOA4F)M)M$**,, $$$***&*oa&8&G## 59"1trA   c                   | j         J | j         D ]+}|                    |            |                                 ,t          j        t
          j        k    r)|                     | j                   \  | _        | _	        dS dS )z"Start the animations of the scene.N)
rf   _setup_scenebeginr   r[   rw   r   rQ  rh   ri   )rI   r   s     rB   begin_animationszScene.begin_animations/  s    *** 	 	I""4(((OO?l000 33DODD$$$$ 10rA   c                    | j         J t          | j         d         t                    o)t          | j                   dk    o| j         d         j        S )zQReturns whether the current animation produces a static frame (generally a Wait).Nr   r   )rf   r   r   r  r   r   s    rB   !is_current_animation_frozen_framez'Scene.is_current_animation_frozen_frame>  sR    ***tq)400 2DO$$)2"1	
rA   skip_renderingc                   | j         J |                     | j                   | _        |                     | j         | j                  | _        | j        D ]w}|                     |           |s(| j        s!| j                            | || j	                   | j
        /| 
                                r| j                                          nx| j         D ]+}|                                 |                    |            ,| j        j        s|                     d           d| j        _        | j                                         dS )aC  
        This method is used to prep the animations for rendering,
        apply the arguments and parameters required to them,
        render them, and write them to the video file.

        Parameters
        ----------
        skip_rendering
            Whether the rendering should be skipped, by default False
        Nr   )rf   r  rk   rd  rj   update_to_timerm   r[   r   rh   rg   closefinishclean_up_from_scenerc   r   static_image)rI   r  tr   s       rB   play_internalzScene.play_internalG  sY    ***))$/:: $ D DOM!
 !
 & 	 	A"""! D$*E D$$T1d.BCCC".43F3F3H3H.%++--- 	0 	0I))$////}, 	$  ###%)"##%%%%%rA   c                   t          | j        t                    sJ t          d         rdS | j        rt          j        d           dS t          d         rt          j        d           dS t          d         r$t          j        dt          d         z              dS | j        j        st          j        d	           dS t          j        rt          j        d
           dS dS )Nforce_windowTzBDisabling interactive embed as 'skip_animation_preview' is enabledFwrite_to_moviez:Disabling interactive embed as 'write_to_movie' is enabledr   z4Disabling interactive embed as '--format' is set as z4Disabling interactive embed as no window was createdz1Disabling interactive embed as dry_run is enabled)	r   r[   r$   r   rm   r   r  windowdry_runr   s    rB    check_interactive_embed_is_validz&Scene.check_interactive_embed_is_validj  s    $-88888.! 	4& 	NT   5$% 	NWXXX5H 	NF"#   5% 	NQRRR5^ 	NNOOO5trA   c                    t           j        t                    sJ t           j        t                    sJ                                  sdS d _        ddlm} d fd}d fd}t          j
                    }|j        j        }dD ]} ||          }|||<   ddlm} ddlm}	 ddlm}
  |
            }d|j        _         |	            |                    |          }n ||          } |	            j        } ||j        d          |_        t3          j        |||f          }|j        sd|_        |                                  j        rht>          d         r[tA          j!                    s2t3          j         j"        ddi          }|                                 n "                    d            j        j#         j        _$         %                    ||           dS )z0Like embed(), but allows for screen interaction.NTr   InteractiveShellEmbedshellr  	namespacedict[str, Any]rE   rF   c                     dd l }dd} |||            ||j        |           d fd}||d<     |           j                            t	          d                     d S )Nr   moduler   r  r  rE   rF   c                P    t          |           D ]}t          | |          ||<   d S rH   )dirr   )r  r  r   s      rB   load_module_into_namespacezLScene.interactive_embed.<locals>.ipython.<locals>.load_module_into_namespace  s8      KK < <D&-fd&;&;IdOO< <rA   rR  rD   c                 ~    j                             t          d                                                      d S )Nkeyboard)rM   rW   r5   exiter)rR  rD   rI   r  s     rB   embedded_rerunz@Scene.interactive_embed.<locals>.ipython.<locals>.embedded_rerun  s1    
1*==>>>rA   rerun)local_nsr  )r  r   r  r  rE   rF   rR  r   rD   r   rE   rF   )manim.openglr&   rM   rW   r4   )r  r  manimr  r  rI   s   `    rB   ipythonz(Scene.interactive_embed.<locals>.ipython  s    < < < < '&ui888&&u|Y???       "0IgE9%%%%JNN0<<=====rA   r|  r9   Callable[..., None]c                8    t          |           dfd}|S )NrR  r   rD   rE   rF   c                 Z    j                             t          | |                     d S rH   )rM   rW   r   )rR  rD   rv  rI   s     rB   embedded_methodzMScene.interactive_embed.<locals>.get_embedded_method.<locals>.embedded_method  s)    
~fdFCCDDDDDrA   r  r   )r|  r  rv  rI   s     @rB   get_embedded_methodz4Scene.interactive_embed.<locals>.get_embedded_method  sE    T;//FE E E E E E E #"rA   )r  r  r   r   )connect)get_ipython)ConfigF)r   )check_same_thread)targetrR  
enable_guir   )r  rD   )r   )r  r  r  r  rE   rF   )r|  r9   rE   r  )&r   r   r"   r[   r$   r  rv   IPython.terminal.embedr  rV  currentframef_backf_localssqlite3r  IPython.core.getipythonr  traitlets.configr  TerminalInteractiveShellconfirm_exitinstancehistory_manager	hist_filedbr  Threadpt_appdaemonstartrr   r   dpgis_dearpygui_running_configure_pyguidefault_model_matrixmodel_matrixinteract)rI   r  r  r  r  local_namespacerv  r  r  r  r  cfgr  histkeyboard_thread
gui_threads   `               rB   interactive_embedzScene.interactive_embed  s~   $+|44444$-888884466 	F $@@@@@@	> 	> 	> 	> 	> 	>*	# 	# 	# 	# 	# 	# #*"6"8"8&-67 	6 	6F11&99O&5OF########777777++++++fhh49$1;== )22#2>>EE))555E{}},'$.EBBB#*)
 
 

 | 	*%)O"" 	3vl'; 	3+-- 3&-0$e,  
   """"%%T%222#';#C e_-----rA   r  r  threading.Threadc                	   t          | j        t                    sJ t          | j                  }t                      }|                    |t          d         d           |                                 d| _	        |j
        d u}| j                                        dk    sJ t          j                    }| j        j        | j        j        j        s| j	        s| j                                        s| j                                        }t          |t"                    r|j        dk    rG|j
        r%|j
        j                            t*                     |                                 t.          |                                 d|j        v r|j        d         t          d<   |                                 |                                 t.          t          |t4                    r|j        dk    r,|j
        r%|j
        j                            t*                     |                                 | j                                        dk    r6| j                                         | j                                        dk    6d}n |j        |j        i |j         nd| j        _        t          j                    |z
  }t          j                    }| j                            | || j                    | !                    |           | "                    |           | #                    |           | j        j        | j        j        j        s| j	        ||r|j
        j                            t*                     |                                 | j                                        dk    r6| j                                         | j                                        dk    6|$                                 |                                 | j%        r t          d	         rtM          j'                     | j        j        1| j        j        j        r"| j        j        (                                 d S d S d S )
N
input_fileT)	recursiveFr   r  )	exceptionfrom_animation_numberr  ))r   r[   r$   rL   rM   r   scheduler   r  quit_interactionr  qsizer   r  
is_closingempty
get_nowaitr5   r8   appexitEOFErrorunschedule_allr)   rc  rD   r4   getrv  rR  animation_start_timer   rh   r   r   r   stoprr   r  stop_dearpyguidestroy)	rI   r  r  event_handlerfile_observerkeyboard_thread_needs_join	last_timeactionr   s	            rB   r  zScene.interact  s*   $-88888)$*55 

}f\.BdSSS %%*\%="z!!Q&&&&IKK	]!-$-2F2Q-$ . :##%% ,%..00f&899 "A}
22 < F!L,11H1EEE%4466611#((***.&-??:@-3;67 $((***!00222--(=>> A}
22u|2(---AAA#((******,,q00
((( ***,,q0016.!FM6;@&-@@@@562Y[[9, IKK	$$T2t/CDDD$$R(((""2&&&  $$$_ ]!-$-2F2Q-$ .d !;L!!H!555  """*""$$q((
    *""$$q(( 	" 	!vl'; 	!   =+0D0O+M ((***** ,+++rA   c                R    t           j        t                    sJ t          d         st	          j        d           d S t          d         rt	          j        d           d S d j        _         j                             d j                   ddl	m
}  |            }|j                            d fd	           t          j                    }t          |t                    sJ |j        j        }d
D ]}t%           |          ||<    ||d           t'          d          )Nr   z4Called embed() while no preview window is available.r  z+embed() is skipped while writing to a file.r   r^  r  post_run_cellc                 F    j                             dj                  S )Nr^  )r[   r   rh   )akwrI   s     rB   <lambda>zScene.embed.<locals>.<lambda>;  s    T]11$D<PQQ rA   )r  r  r   r   r  r   )r  stack_depthzExiting scene.)r   r[   r$   r   r   r  r  r   rh   r  r  eventsregisterrV  r  r0   r  r  r   	Exception)rI   r  r  current_framer  rv  s   `     rB   embedzScene.embed'  sX   $-88888i  	NQRRRF"# 	NHIIIF-.*T2t';<<< 	A@@@@@%%'' 	QQQQ	
 	
 	
  ,..-33333 '0	
 
	5 
	5F  'tV44HVxQ//// ()))rA   r   c           	     b     j         st          d          |rt          j        t                     n9t          j                     t          j                     t          j                     t          j        dt                      t          j
        d           t          j        d           d' fd}d' fd}d' fd}t          t          t          d                   d          }d |D             }t          j        t          dt          d         d         t          d         d         gdd          5  t          j        d           t          j        d|           t          j        d|           t          j        d||t          d         d                    t          j                     t'           j                  dk    rt          j        t          d         d          d d!          5   j        D ]f}|                                }|d"         }	|d#         }
|
d$k    r'|d"= |d#=  t/          t          d%|
           d(d&|	i| St          j                     g	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |st          j                     d S d S ))Nz2Attempted to use DearPyGUI when it isn't imported.zManim Community v)titlei  i  r8   r   datarE   rF   c                V    j                             t          d                     d S NguirV   r8   r  rI   s     rB   rerun_callbackz.Scene._configure_pygui.<locals>.rerun_callbackb  s&    JNN-e4455555rA   c                V    j                             t          d                     d S r   )rM   rW   r4   r"  s     rB   continue_callbackz1Scene._configure_pygui.<locals>.continue_callbacke  s&    JNN07788888rA   c                    t          j        |           ft          d<   j                            t          d                     d S )Nscene_namesr!  )r  	get_valuer   rM   rW   r5   r"  s     rB   scene_selection_callbackz8Scene._configure_pygui.<locals>.scene_selection_callbackh  s=    %(]6%:%:$<F=!JNN-e4455555rA   r  T)	full_listc                    g | ]	}|j         
S r@   )r:   )r   scene_classs     rB   r   z*Scene._configure_pygui.<locals>.<listcomp>o  s    MMM{+MMMrA   z	Manim GUIgui_locationr   r   i  i  )r   labelposwidthheightr   Rerun)r.  callbackContinuezSelected scener'  )r.  r   r3  default_valuez widgets)r.  default_openr   widget	separatoradd_r.  )r8   r   r  r   rE   rF   r@   )rr   RuntimeErrorr  delete_itemr  create_viewportsetup_dearpyguishow_viewportset_viewport_titler   set_viewport_widthset_viewport_heightr/   r	   r   set_global_font_scale
add_button	add_comboadd_separatorr  rq   collapsing_headerr   r   start_dearpygui)rI   r   r#  r%  r)  scene_classesr'  widget_configwidget_config_copyr   r7  s   `          rB   r  zScene._configure_pyguiT  s   & 	USTTT 	 OF####!!!!!!%F%F%FGGGGt$$$$$$	6 	6 	6 	6 	6 	6	9 	9 	9 	9 	9 	9	6 	6 	6 	6 	6 	6 0%&&$
 
 
 NM}MMMZ'*F>,B1,EF
 
 
 !	0 !	0 %a(((N>BBBBN6GHHHHM&!1$]3A6	    4<  A%%*#M215???!%   0 0 *. 0 0-:-?-?-A-A*1&9!3H!=![00 26 : 28 <9GC99  &*.@     -////0	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0%!	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0 !	0F  	"!!!!!	" 	"s8   ;B?J:A/I6*J6I:	:J=I:	>JJJr  c                4   || j         z
  }|| _         | j        J | j        D ]6}|                    |           ||j        z  }|                    |           7|                     |           |                     |           |                     |           d S rH   )rl   rf   r   re  interpolater   r   )rI   r  r   r   alphas        rB   r  zScene.update_to_time  s    _*** 	) 	)I%%b)))	**E!!%((((R   2rA   r   r  r  c                \   t          j        t          | j        j        j                  |t          j        t          | j	        |z                       t          j        t          | j	        |z   |z                                 }| j        j        j        
                    |           dS )ay  Adds an entry in the corresponding subcaption file
        at the current time stamp.

        The current time stamp is obtained from ``Scene.time``.

        Parameters
        ----------

        content
            The subcaption content.
        duration
            The duration (in seconds) for which the subcaption is shown.
        offset
            This offset (in seconds) is added to the starting time stamp
            of the subcaption.

        Examples
        --------

        This example illustrates both possibilities for adding
        subcaptions to Manimations::

            class SubcaptionExample(Scene):
                def construct(self):
                    square = Square()
                    circle = Circle()

                    # first option: via the add_subcaption method
                    self.add_subcaption("Hello square!", duration=1)
                    self.play(Create(square))

                    # second option: within the call to Scene.play
                    self.play(
                        Transform(square, circle), subcaption="The square transforms."
                    )

        )seconds)indexr  r  endN)srtSubtitler  r[   r   subcaptionsdatetime	timedeltar   r   r   )rI   r  rk   r  subtitles        rB   r  zScene.add_subcaption  s    P <dm/;<<$U49v3E-F-FGGG"5V1Ch1N+O+OPPP	
 
 
 	!-44X>>>>>rA   
sound_filetime_offsetgainc                j    | j         j        rdS | j        |z   } | j         j        j        |||fi | dS )a  
        This method is used to add a sound to the animation.

        Parameters
        ----------

        sound_file
            The path to the sound file.
        time_offset
            The offset in the sound file after which
            the sound can be played.
        gain
            Amplification of the sound.

        Examples
        --------
        .. manim:: SoundExample
            :no_autoplay:

            class SoundExample(Scene):
                # Source of sound under Creative Commons 0 License. https://freesound.org/people/Druminfected/sounds/250551/
                def construct(self):
                    dot = Dot().set_color(GREEN)
                    self.add_sound("click.wav")
                    self.add(dot)
                    self.wait()
                    self.add_sound("click.wav")
                    dot.set_color(BLUE)
                    self.wait()
                    self.add_sound("click.wav")
                    dot.set_color(RED)
                    self.wait()

        Download the resource for the previous example `here <https://github.com/ManimCommunity/manim/blob/main/docs/source/_static/click.wav>`_ .
        N)r[   rc   r   r   	add_sound)rI   rX  rY  rZ  rD   r   s         rB   r\  zScene.add_sound  sM    T =( 	Fy;&+!+JdMMfMMMMMrA   pointr3   d_pointc                   t          | j        t                    sJ t          | j        t                    sJ | j                            |           t          | j        j        v r| }|dxx         | j        	                                dz  z  cc<   |dxx         | j        
                                dz  z  cc<   | j        j        }t          j        t          j        |          |          }| j                            |           d S d S )Nr   r   r   )r   r   r"   r[   r$   ry   move_toSHIFT_VALUEpressed_keys	get_width
get_heightinverse_rotation_matrixr   dot	transposeshift)rI   r]  r^  rh  	transforms        rB   on_mouse_motionzScene.on_mouse_motion  s    $+|44444$-88888  '''$-444HE!HHH--//!33HHH!HHH..00144HHH;IF2<	22E::EKe$$$$$ 54rA   c                   t          | j        t                    sJ t          j        sAdt          j        d|d         z            z   }| j                            || j                   | 	                    ||           d S )Nr   g )about_point)
r   r   r"   r   use_projection_stroke_shadersr   arctanscalerp   mouse_scroll_orbit_controls)rI   r]  r  factors       rB   on_mouse_scrollzScene.on_mouse_scroll  s}    $+|444443 	F4&)#3444FKf$2DEEE((77777rA   symbolint	modifiersc                   t          | j        t                    sJ 	 t          |          }n%# t          $ r t          j        d           Y d S w xY w|dk    rB| j                                         t          j	        g dt          j
                  | _        d S |dk    r	d| _        d S || j        v r | j        |                      d S d S )Nz*The value of the pressed key is too large.r)r   r   r   )dtypeqT)r   r   r"   chrOverflowErrorr   r  to_default_stater   arrayfloat32rp   r  rt   )rI   rs  ru  chars       rB   on_key_presszScene.on_key_press  s    $+|44444	v;;DD 	 	 	NGHHHFF	 3;;K((***!#)))2:!F!F!FDS[[$(D!!!t///.(.00000 0/s   . AAc                    d S rH   r@   )rI   rs  ru  s      rB   on_key_releasezScene.on_key_release&  s    rA   buttonsc                   t          | j        t                    sJ | j                            |           |dk    rB| j                            |d                     | j                            |d                    nn|dk    rh| j        j        d ddf         }|d          |z  }|d          t          j	        t          |          z  }||z   }| j                            d|z             |                     ||||           d S )Nr   r         g?)r   r   r"   rz   r`  increment_thetaincrement_phir  r   crossOUTrh  mouse_drag_orbit_controls)	rI   r]  r^  r  ru  camera_x_axishorizontal_shift_vectorvertical_shift_vectortotal_shift_vectors	            rB   on_mouse_dragzScene.on_mouse_drag)  s    $+|44444%%e,,,a<<K''444K%%gaj1111\\ K4RaRU;M'.qzkM&A#%,QZK"(32N2N$N!!8;P!PKc$66777&&ugw	JJJJJrA   c                   t          | j        t                    sJ | j        | j                                        z
  }|t          j        |d                   z  }d|z  }t          j        | | j        j	        z  | j        _	        d S )Nr   g{Gz?)
r   r   r"   rp   get_positionr   signr&   translation_matrixr  )rI   r]  r  camera_to_targetshift_vectors        rB   rp  z!Scene.mouse_scroll_orbit_controls>  s    $+|44444-0H0H0J0JJBGF1I.....%|4t{7OO 	   rA   c                   t          | j        t                    sJ |dk    rNt          j        |d                    t          j        | j          z  | j        j        z  | j        _        | j                                        }| j        j        d ddf         }t          j
        t          j        ||                    }t          j        |d         |d          }| j        j        }	| j        j        }
|| j        j        z  }|d ddf         }|d ddf         }|d         dk    rt          j        |d                   nd}|t          j        |d         t          j                            |          z            z  }|
|cxk    r|	k    rn n|| j        _        n|d         dk    rt          j        |d                   nd}|t          j        |d         t          j                            |          z            z  }||	k    r|	|z
  }n|
|z
  }t          j        ||d          }|| j        j        z  | j        _        t          j        | j         | j        j        z  | j        _        d S |dk    r| j        j        d ddf         }|d          |z  }|d          t          j        t&          |          z  }||z   }t          j        | | j        j        z  | j        _        | xj        |z  c_        d S d S )	Nr   r   )zr  T)homogeneousr   r  )r   r   r"   r&   rotation_matrixr  rp   r  r  r'   	normalizer   r  maximum_polar_angleminimum_polar_angler  arccoslinalgnormr  )rI   r]  r^  r  ru  camera_positioncamera_y_axisaxis_of_rotationr  r  r  potential_camera_model_matrixpotential_camera_locationpotential_camera_y_axisr  potential_polar_anglecurrent_polar_anglepolar_angle_deltar  r  r  r  s                         rB   r  zScene.mouse_drag_orbit_controlsG  sZ    $+|44444a<< &'!*555+d.@-@AB+*+ K$ #k6688O K4RaRU;M(288    (7
    O #'+"A"&+"A,;dk>V,V)(Ebqb!e(L%&CBQBE&J# +1-22 /2333 
 %)29)!,)..!:;;<, , %! #&;RRRR?RRRRRR+H((4A!4D4I4Irw}Q/000q&*RY#A&)H)HH. . '# )+>>>(;>Q(Q%%(;>Q(Q%"+";%$ $# # #
 ,;T[=U+U( )4+=>+*+ K$$$
 \\ K4RaRU;M'.qzkM&A#%,QZK"(32N2N$N!!8;P!P )+=>+*+ K$ "44 \rA   r  Callable[[], Any]c                    || j         |<   d S rH   )rt   )rI   r  r   s      rB   set_key_functionzScene.set_key_function  s    )- &&&rA   buttonc                .    | j         D ]} |             d S rH   )ru   )rI   r]  r  ru  r   s        rB   on_mouse_presszScene.on_mouse_press  s+    . 	 	DDFFFF	 	rA   )r[   r\   r]   r^   r_   r`   ra   rb   rc   r`   rE   rF   )rE   r   )rE   r   )r   r   rE   r   )F)r   r`   rE   r`   )rE   rF   )r   r9   r   r9   rc   r`   rE   rF   )rE   r9   )r   r9   rE   r   )r   r   rE   rF   )rE   r`   )rE   r   )r|   r   rE   r1   )rf   r   rE   rF   )r|   r   rE   r1   )r  r   r  r   rE   rF   )r   r  rE   rF   )r|   T)r   r  r   r9   r  r`   rE   r   )r|   r$  r   r$  rE   r   )r|   r   rE   r   )r   r   rE   r   )r   r   rE   r   )rE   r1   )rf   r   rE   r   )rf   r@  rE   rK  )rR  rS  rD   r   rE   r   )rf   r   rk   r   rE   r\  )NF)
re  r   rf  r9   r_  rb   r`  r`   rE   r\  r  )re  r   rv  rw  rx  r9   rE   r   )rf   r   rE   r   )rR  rS  r  r  r  r  r  r   rD   r   rE   rF   )rk   r   rg   r  r  r  rE   rF   )rk   r   rE   rF   )r  )rg   r  r  r   rE   rF   )rf   rS  r  r   rE   r  )r  r`   rE   rF   )r  r   r  r  rE   rF   )T)r   r`   rE   rF   )r  r   rE   rF   )r   r   )r  r9   rk   r   r  r   rE   rF   )r   N)
rX  r9   rY  r   rZ  r  rD   r   rE   rF   )r]  r3   r^  r3   rE   rF   )r]  r3   r  r3   rE   rF   )rs  rt  ru  rt  rE   rF   )
r]  r3   r^  r3   r  rt  ru  rt  rE   rF   )r  r9   r   r  rE   rF   )r]  r3   r  r9   ru  rt  rE   rF   )Jr:   r;   r<   r=   r   rJ   propertyr   r   r   r   r   r   r   r   NORMALr   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r!  r/  r2  r4  r6  r8  r:  r<  rJ  rQ  r[  rd  rb  classmethodr  r  r  DEFAULT_WAIT_TIMEr  r  r  r  r  r  r  r  r  r  r  r  r  r  r\  rj  rr  r  r  r  rp  r  r  r  r@   rA   rB   r   r      s5        @ ;?%+',"& %6) 6) 6) 6) 6)p $ $ $ X$ " " " X"   ) ) ) ) )V         F .5 %	
T 
T 
T 
T 
T' ' ' '4 4 4 4 
 
 
 
       
   &1 1 1 1:9 9 9 9&   0* * * *X
2 
2 
2 
2$ $ $ $L:G :G :G :Gx# # # #>D D D D$ ",!%	) ) ) ) )V$ $ $ $N   &5 5 5 5"   $8 8 8 8"   &   (    . . . .`< < < <(* * * *X2  2  2  2 p $()..  .  .  .  . ` 
 )	    [8   , "&,0#$< < < < < <@ ,48$(	"
 "
 "
 "
 "
H '8 8 8 8 8 8& EG; ; ; ; ; . . . .`E E E E
 
 
 
!& !& !& !& !&F   4P. P. P. P.hM+ M+ M+ M+^+* +* +* +*ZA" A" A" A" A"F
 
 
 
 BC.? .? .? .? .?f !	-N -N -N -N -N^
% 
% 
% 
%8 8 8 81 1 1 1"   K K K K*
 
 
 
N5 N5 N5 N5`. . . .     rA   )gr=   
__future__r   manim.utils.parameter_parsingr   mobject.mobjectr   __all__r   rU  rV  rr  r~   r  r   dataclassesr   pathlibr	   rM   r
   rR  manim.scene.sectionr   dearpygui.dearpygui	dearpyguir  rr   create_contextgenerate_uuidr  ImportErrorcollections.abcr   r   r   typingr   r   numpyr   r   watchdog.eventsr   r   r   watchdog.observersr   r  r   manim.data_structuresr   manim.mobject.mobjectr   #manim.mobject.opengl.opengl_mobjectr   ra  r   r   animation.animationr   r   r   camera.camerar   	constantsrenderer.cairo_rendererr!   renderer.opengl_rendererr"   r#   r$   renderer.shaderr%   utilsr&   r'   utils.exceptionsr(   r)   utils.familyr*   utils.family_opsr+   utils.file_opsr,   utils.iterablesr-   r.   utils.module_opsr/   typesr0   r1   r2   manim.typingr3   r6   r?   r4   r5   rL   r   r@   rA   rB   <module>r     so   " " " " " " " " " E E E E E E / / / / / /)           ! ! ! ! ! !             



 2 2 2 2 2 2%%%%%%CS  FF    9 8 8 8 8 8 8 8 8 8 % % % % % % % %           W W W W W W W W W W ' ' ' ' ' '       0 0 0 0 0 0 ) ) ) ) ) ) ; ; ; ; ; ;         D D D D D D D D D D " " " " " "     3 3 3 3 3 3 R R R R R R R R R R & & & & & & % % % % % % % % J J J J J J J J 9 9 9 9 9 9 Q Q Q Q Q Q , , , , , , A A A A A A A A 6 6 6 6 6 6 &&&&&&&&$$$$$$ 	003GG             $       .3 3 3 3 3. 3 3 3Q Q Q Q Q Q Q Q Q Qs   &A9 9BB