
    ^j                        d Z ddlmZ ddlmZ erddlmZ ddlmZmZ ddl	m
Z
  G d d          Z G d	 d
          ZdS )a  2D Animations.

Animations can be used by the :py:class:`~pyglet.sprite.Sprite` class in place
of static images. They are essentially containers for individual image frames,
with a duration per frame. They can be infinitely looping, or stop at the last
frame. You can load Animations from disk, such as from GIF files::

    ani = pyglet.resource.animation('walking.gif')
    sprite = pyglet.sprite.Sprite(img=ani)

Alternatively, you can create your own Animations from a sequence of images
by using the :py:meth:`~Animation.from_image_sequence` method::

    images = [pyglet.resource.image('walk_a.png'),
              pyglet.resource.image('walk_b.png'),
              pyglet.resource.image('walk_c.png')]

    ani = pyglet.image.Animation.from_image_sequence(images, duration=0.1, loop=True)

You can also use an :py:class:`pyglet.image.ImageGrid`, which is iterable::

    sprite_sheet = pyglet.resource.image('my_sprite_sheet.png')
    image_grid = pyglet.image.ImageGrid(sprite_sheet, rows=1, columns=5)

    ani = pyglet.image.Animation.from_image_sequence(image_grid, duration=0.1)

In the above examples, all the Animation Frames have the same duration.
If you wish to adjust this, you can manually create the Animation from a list of
:py:class:`~AnimationFrame`::

    image_a = pyglet.resource.image('walk_a.png')
    image_b = pyglet.resource.image('walk_b.png')
    image_c = pyglet.resource.image('walk_c.png')

    frame_a = pyglet.image.AnimationFrame(image_a, duration=0.1)
    frame_b = pyglet.image.AnimationFrame(image_b, duration=0.2)
    frame_c = pyglet.image.AnimationFrame(image_c, duration=0.1)

    ani = pyglet.image.Animation(frames=[frame_a, frame_b, frame_c])

    )annotations)TYPE_CHECKING)Literal)AbstractImageAbstractImageSequence)
TextureBinc                  l    e Zd ZdZd!dZd"d#dZ	 	 d$d%dZd&dZd'dZd'dZ	e
d(d)d            Zd*dZd S )+	Animationaq  Sequence of images with timing information.

    Animations are a collection of :py:class:`~AnimationFrame`s, which are
    simple containers for Image data and duration information.

    If no frames of the animation have a duration of ``None``, the animation
    loops continuously; otherwise the animation stops at the first frame with
    duration of ``None``.
    frameslist[AnimationFrame]returnNonec                6    t          |          sJ || _        dS )z3Create an animation directly from a list of frames.Nlenr   )selfr   s     Q/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/image/animation.py__init__zAnimation.__init__@   s    6{{{    r   texture_binr   borderintc                Z    | j         D ]"}|                    |j        |          |_        #dS )a2  Add the images of the animation to a :py:class:`~pyglet.image.atlas.TextureBin`.

        The animation frames are modified in-place to refer to the texture bin
        regions. An optional border (in pixels) can be specified to reserve around
        the images that are added to the texture bin.
        N)r   addimage)r   r   r   frames       r   add_to_texture_binzAnimation.add_to_texture_binE   s8     [ 	? 	?E%//%+v>>EKK	? 	?r   Fflip_xboolflip_yrotateLiteral[0, 90, 180, 270, 360]c                P    fd| j         D             }t          |          S )a  Create a copy of this animation, applying a simple transformation.

        The transformation is performed by manipulating the texture coordinates,
        which limits this operation to increments of 90 degrees.

        The transformation is applied around the image's anchor point of
        each frame.  The texture data is shared between the original animation
        and the transformed animation.
        c           	         g | ]C}t          |j                                                                      |j                  DS  )AnimationFramer   get_textureget_transformduration).0r   r   r    r!   s     r   
<listcomp>z+Animation.get_transform.<locals>.<listcomp>Z   sb     K K K5: !!8!8!:!:!H!HQWY_!`!`!&1 1 K K Kr   )r   r
   )r   r   r    r!   r   s    ``` r   r(   zAnimation.get_transformO   sP    K K K K K K>BkK K K   r   floatc                >    t          d | j        D                       S )z3Get the total duration of the animation in seconds.c                *    g | ]}|j         	|j         S )Nr)   r*   r   s     r   r+   z*Animation.get_duration.<locals>.<listcomp>`   s!    ZZZuu~?YEN?Y?Y?Yr   )sumr   r   s    r   get_durationzAnimation.get_duration^   s!    ZZZZZ[[[r   c                >    t          d | j        D                       S )zGet the maximum image frame width.

        This method is useful for determining texture space requirements: due
        to the use of ``anchor_x`` the actual required viewing area during
         playback may be larger.
        c                &    g | ]}|j         j        S r%   )r   widthr0   s     r   r+   z+Animation.get_max_width.<locals>.<listcomp>i   s    ???%EK%???r   maxr   r2   s    r   get_max_widthzAnimation.get_max_widthb   s#     ??4;???@@@r   c                >    t          d | j        D                       S )zGet the maximum image frame height.

        This method is useful for determining texture space requirements: due
        to the use of ``anchor_y`` the actual required viewing area during
        playback may be larger.
        c                &    g | ]}|j         j        S r%   )r   heightr0   s     r   r+   z,Animation.get_max_height.<locals>.<listcomp>r   s    @@@5EK&@@@r   r7   r2   s    r   get_max_heightzAnimation.get_max_heightk   s#     @@DK@@@AAAr   Tsequencer   r)   loopc                T    fd|D             }|sd|d         _          | |          S )zCCreate an animation from a list of images and a per-frame duration.c                0    g | ]}t          |          S r%   )r&   )r*   r   r)   s     r   r+   z1Animation.from_image_sequence.<locals>.<listcomp>w   s#    HHHe.11HHHr   Nr/   )clsr>   r)   r?   r   s     `  r   from_image_sequencezAnimation.from_image_sequencet   sA     IHHHxHHH 	'"&F2Js6{{r   strc                2    dt          | j                   dS )NzAnimation(frames=)r   r2   s    r   __repr__zAnimation.__repr__|   s    63t{#3#36666r   N)r   r   r   r   )r   )r   r   r   r   r   r   )FFr   )r   r   r    r   r!   r"   r   r
   )r   r,   )r   r   )T)r>   r   r)   r,   r?   r   r   r
   r   rE   )__name__
__module____qualname____doc__r   r   r(   r3   r9   r=   classmethodrD   rH   r%   r   r   r
   r
   5   s            
? ? ? ? ? BG>?! ! ! ! !\ \ \ \A A A AB B B B     [7 7 7 7 7 7r   r
   c                  &    e Zd ZdZdZdd	ZddZdS )r&   zA single frame of an animation.r   r)   r   r   r)   float | Noner   r   c                "    || _         || _        dS )z(Create an animation frame from an image.NrP   )r   r   r)   s      r   r   zAnimationFrame.__init__   s    
 r   rE   c                (    d| j          d| j         dS )NzAnimationFrame(z, duration=rG   rP   r2   s    r   rH   zAnimationFrame.__repr__   s    HHHHHHHr   N)r   r   r)   rQ   r   r   rI   )rJ   rK   rL   rM   	__slots__r   rH   r%   r   r   r&   r&      sM        ))#I! ! ! !
I I I I I Ir   r&   N)rM   
__future__r   typingr   r   pyglet.imager   r   pyglet.image.atlasr   r
   r&   r%   r   r   <module>rY      s   ( (R # " " " " " !           .AAAAAAAA------H7 H7 H7 H7 H7 H7 H7 H7VI I I I I I I I I Ir   