
    lj                        d Z ddlmZ dgZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lT ddlmZ ddlmZ ddlmZ erddlmZmZ  G d de          ZdS )a-  A scene supporting zooming in on a specified section.


Examples
--------

.. manim:: UseZoomedScene

    class UseZoomedScene(ZoomedScene):
        def construct(self):
            dot = Dot().set_color(GREEN)
            self.add(dot)
            self.wait(1)
            self.activate_zooming(animate=False)
            self.wait(1)
            self.play(dot.animate.shift(LEFT))

.. manim:: ChangingZoomScale

    class ChangingZoomScale(ZoomedScene):
        def __init__(self, **kwargs):
            ZoomedScene.__init__(
                self,
                zoom_factor=0.3,
                zoomed_display_height=1,
                zoomed_display_width=3,
                image_frame_stroke_width=20,
                zoomed_camera_config={
                    "default_frame_stroke_width": 3,
                },
                **kwargs
            )

        def construct(self):
            dot = Dot().set_color(GREEN)
            sq = Circle(fill_opacity=1, radius=0.2).next_to(dot, RIGHT)
            self.add(dot, sq)
            self.wait(1)
            self.activate_zooming(animate=False)
            self.wait(1)
            self.play(dot.animate.shift(LEFT * 0.3))

            self.play(self.zoomed_camera.frame.animate.scale(4))
            self.play(self.zoomed_camera.frame.animate.shift(0.5 * DOWN))

    )annotationsZoomedScene)TYPE_CHECKINGAny   )ApplyMethod)Camera)MovingCamera)MultiCamera)*)ImageMobjectFromCamera)OpenGLCamera)MovingCameraScene)Point3DLikeVector3Dc                  z     e Zd ZdZedddeez   edddi edddfd) fd Z	d* fd!Z
d+d,d#Zd-d.d&Zd/d'Zd0d(Z xZS )1r   zThis is a Scene with special configurations made for when
    a particular part of the scene must be zoomed in on and displayed
    separately.
       Nr      )default_frame_stroke_widthbackground_opacityg333333?Fcamera_classtype[Camera]zoomed_display_heightfloatzoomed_display_widthzoomed_display_centerPoint3DLike | Nonezoomed_display_cornerr   zoomed_display_corner_buffzoomed_camera_configdict[str, Any]"zoomed_camera_image_mobject_config%zoomed_camera_frame_starting_positionr   zoom_factorimage_frame_stroke_widthzoom_activatedboolkwargsr   returnNonec                    || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
         t                      j        dd|i| d S )Nr    )r   r   r   r   r   r    r"   r#   r$   r%   r&   super__init__)selfr   r   r   r   r   r   r    r"   r#   r$   r%   r&   r(   	__class__s                 S/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/scene/zoomed_scene.pyr.   zZoomedScene.__init__L   s    & &;"$8!%:"%:"*D'$8!2T/1 	2 '(@%,==l=f=====    c                T   t                                                       t          di | j        }t	          |fi | j        }|                                 |j        |fD ]6}|                    | j	                   |
                    | j                   7|j                            | j                   |j                            | j                   | j        |                    | j                   n!|                    | j        | j                   || _        || _        dS )z[This method is used internally by Manim to
        setup the scene for proper use.
        N)buffr,   )r-   setupr
   r    r   r"   add_display_frameframestretch_to_fit_heightr   stretch_to_fit_widthr   scaler$   move_tor#   r   	to_cornerr   r   zoomed_camerazoomed_display)r/   r=   r>   mobr0   s       r1   r5   zZoomedScene.setupn   sF    	$AAt'@AA/
 
!D
 
 	((*** &6 	@ 	@C%%d&@AAA$$T%>????!!$"2333 	##D$NOOO%1""4#=>>>>$$*4 %   
 +,r2   animatec                F   d| _         | j        j                            | j                   |rN|                     |                                            |                     |                                            |                     | j	        j
        | j                   dS )zThis method is used to activate the zooming for the zoomed_camera.

        Parameters
        ----------
        animate
            Whether or not to animate the activation
            of the zoomed camera.
        TN)r&   renderercameraadd_image_mobject_from_camerar>   playget_zoom_in_animation$get_zoomed_display_pop_out_animationadd_foreground_mobjectsr=   r7   )r/   r@   s     r1   activate_zoomingzZoomedScene.activate_zooming   s     #::4;NOOO 	CIId0022333IId??AABBB$$$	
 	
 	
 	
 	
r2   run_timer   c                   | j         j        }t          | j        t                    r| j        j        \  }}n| j        j        }| j        j        }|                                 |	                    |           |
                    |           |                                 |                    d           t          |j        fd|i|S )ac  Returns the animation of camera zooming in.

        Parameters
        ----------
        run_time
            The run_time of the animation of the camera zooming in.
        **kwargs
            Any valid keyword arguments of ApplyMethod()

        Returns
        -------
        ApplyMethod
            The animation of the camera zooming in.
        r   )widthrJ   )r=   r7   
isinstancerC   r   frame_shapeframe_heightframe_width
save_stater9   r8   center
set_stroker   restore)r/   rJ   r(   r7   full_frame_widthfull_frame_heights         r1   rF   z!ZoomedScene.get_zoom_in_animation   s     "(dk<00 	726+2I/// $ 8#{6""#3444##$5666q!!!5=FF8FvFFFr2   c                    | j         }|                                 |                    | j        j        d           t          |j                  S )zThis is the animation of the popping out of the mini-display that
        shows the content of the zoomed camera.

        Returns
        -------
        ApplyMethod
            The Animation of the Zoomed Display popping out.
        T)stretch)r>   rQ   replacer=   r7   r   rT   )r/   r(   displays      r1   rG   z0ZoomedScene.get_zoomed_display_pop_out_animation   sJ     %*0$???7?+++r2   c                B    | j         j        j        | j        j        z  }|S )zReturns the Zoom factor of the Zoomed camera.

        Defined as the ratio between the height of the zoomed camera and
        the height of the zoomed mini display.

        Returns
        -------
        float
            The zoom factor.
        )r=   r7   heightr>   )r/   r$   s     r1   get_zoom_factorzZoomedScene.get_zoom_factor   s(     $+d.A.HH 	 r2   )r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r!   r#   r   r$   r   r%   r   r&   r'   r(   r   r)   r*   )r)   r*   )F)r@   r'   r)   r*   )r   )rJ   r   r(   r   r)   r   )r(   r   r)   r   )r)   r   )__name__
__module____qualname____doc__r   UPRIGHTDEFAULT_MOBJECT_TO_EDGE_BUFFERORIGINr.   r5   rI   rF   rG   r]   __classcell__)r0   s   @r1   r   r   F   s         &1'(&'48*,u*,J*+"#0
 0
 >@=C!*+$! >  >  >  >  >  >  >D- - - - - -:
 
 
 
 
&G G G G G8, , , ,       r2   N)ra   
__future__r   __all__typingr   r   animation.transformr   camera.camerar	   camera.moving_camerar
   camera.multi_camerar   	constantsmobject.types.image_mobjectr   renderer.opengl_rendererr   scene.moving_camera_scener   manim.typingr   r   r   r,   r2   r1   <module>rs      s,  - -^ # " " " " "/ % % % % % % % % - - - - - - " " " " " " / / / / / / - - - - - -     @ @ @ @ @ @ 3 3 3 3 3 3 9 9 9 9 9 9 322222222P P P P P# P P P P Pr2   