ó
X–Tc           @   sb   d  Z  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 S(
   s™   Animations interpolate a property between two values over a number of frames.
They can be combined to run at the same time, or directly after each other.t	   Animationc           B   sP   e  Z d  Z d e d e d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   sï  
    Creates an animation on *property*, with the specified
    *easing*, to last *duration* in seconds.

    The following example shows a Sprite with an animation that will linearly
    change its 'x' property from 0 to 100 over 2 seconds.::

        from spyral import Sprite, Animation, easing
        ...
        my_sprite = Sprite(my_scene)
        my_animation = Animation('x', easing.Linear(0, 100), 2.0)
        my_sprite.animate(my_animation)

    Animations can be appended one after another with the `+`
    operator, and can be run in parallel with the `&` operator.

    >>> from spyral import Animation, easing
    >>> first  = Animation('x', easing.Linear(0, 100), 2.0)
    >>> second = Animation('y', easing.Linear(0, 100), 2.0)
    # Sequential animations
    >>> right_angle = first + second
    # Parallel animations
    >>> diagonal = first & second

    :param property: The property of the sprite to change (e.g., 'x')
    :type property: :class:`string`
    :param easing: The easing (rate of change) of the property.
    :type easing: :class:`Easing <spyral.Easing>`
    :param duration: How many seconds to play the animation
    :type duration: :class:`float`
    :param absolute: (**Unimplemented?**) Whether to position this relative
                     to the sprite's offset, or to absolutely position it on the
                     screen.
    :type absolute: :class:`boolean`
    :param shift: How much to offset the animation (a number if the property is
                  scalar, a :class:`Vec2D <spyral.Vec2D>` if the property is
                  "pos", and None if there is no offset.
    :type shift: None, a :class:`Vec2D <spyral.Vec2D>`, or a number
    :param loop: Whether to loop indefinitely
    :type loop: :class:`boolean`
    g      ð?c         C   sL   | |  _  | |  _ | |  _ | |  _ | |  _ t | f ƒ |  _ | |  _ d  S(   N(   t   absolutet   propertyt   easingt   durationt   loopt   sett
   propertiest   _shift(   t   selfR   R   R   R   t   shiftR   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   __init__/   s    						c         C   sˆ   | |  j  } |  j | | ƒ } |  j d k	 rz |  j d k rj | d |  j d | d |  j d f } qz | |  j } n  i | |  j 6S(   sA  
        For a given *sprite*, complete *progress*'s worth of this animation.
        Basically, complete a step of the animation. Returns a dictionary
        representing the changed property and its new value, e.g.:
        :code:`{"x": 100}`. Typically, you will use the sprite's animate function instead of calling
        this directly.

        :param sprite: The Sprite that will be manipulated.
        :type sprite: :class:`Sprite <spyral.Sprite>`
        :param float progress: The amount of progress to make on this animation.
        :rtype: :class:`dict`
        t   posi    i   N(   R   R   R   t   NoneR   (   R	   t   spritet   progresst   value(    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   evaluate@   s    c         C   s   t  |  | ƒ S(   N(   t   MultiAnimation(   R	   t   second(    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   __and__W   s    c         C   s   t  |  | ƒ S(   N(   R   (   R	   R   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   __iand__Z   s    c         C   s   t  |  | ƒ S(   N(   t   SequentialAnimation(   R	   R   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   __add__]   s    c         C   s   t  |  | ƒ S(   N(   R   (   R	   R   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   __iadd__`   s    N(   t   __name__t
   __module__t   __doc__t   TrueR   t   FalseR   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR       s   )				R   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sm  
    Class for creating parallel animation from two other animations.

    This does not respect the absolute setting on individual
    animations. Pass absolute as a keyword argument to change,
    default is True.
    Absolute applies only to numerical properties.

    loop is accepted as a kwarg, default is True if any child
    loops, or False otherwise.
    c   
      O   s›  t  ƒ  |  _ g  |  _ d |  _ | j d t ƒ |  _ t |  _ x’ | D]Š } | j j	 |  j ƒ } | r} d } t
 | | ƒ ‚ n  |  j j | j ƒ |  j j | ƒ t |  j | j ƒ |  _ | j rC t |  _ qC qC Wd t  d d g ƒ f d t  d d	 d
 g ƒ f d
 t  d d	 d g ƒ f g } x` | D]X \ } } |  j j	 | ƒ }	 | |  j k r#|	 r#d } t
 | | |	 j ƒ  f ƒ ‚ q#q#W| j d |  j ƒ |  _ d  S(   Ni    R   s/   Cannot animate on the same properties twice: %st   scalet   scale_xt   scale_yR   t   xt   yt   positions2   Cannot animate on %s and %s in the same animation.R   (   R   R   t   _animationsR   t   getR   R   R   R   t   intersectiont
   ValueErrort   updatet   appendt   maxt   pop(
   R	   t
   animationst   kwargst	   animationt   it   messaget   clobbering_animationst   propt   otherst   overlapping_properties(    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   p   s2    					c         C   se   i  } xX |  j  D]M } | | j k rA | j | j | | ƒ ƒ q | j | j | | j ƒ ƒ q W| S(   N(   R$   R   R(   R   (   R	   R   R   t   resR.   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   Œ   s     (   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   d   s   	R   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sz  
    An animation that represents the input animations in sequence.

    loop is accepted as a kwarg, default is False.

    If the last animation in a SequentialAnimation is set to loop,
    that animation will be looped indefinitely at the end, but not
    the entire SequentialAnimation. If loop is set to true, the
    entire SequentialAnimation will loop indefinitely.
    c         O   sì   t  ƒ  |  _ | |  _ d |  _ t |  _ | j d t ƒ |  _ x| | D]t } |  j j	 | j ƒ |  j | j 7_ |  j r | j r t
 d ƒ ‚ n  | j rC | | d k	 rC t
 d ƒ ‚ qC qC W| d j t k rè |  j | d j |  _ n  d  S(   Ni    R   s^   Looping sequential animation with a looping animation anywhere in the sequence is not allowed.iÿÿÿÿs=   Looping animation in the middle of a sequence is not allowed.(   R   R   R$   R   R   R   R%   R   R   R(   R'   (   R	   R,   R-   R.   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   ¡   s    			c         C   sé   i  } | |  j  k rC | j |  j d j | |  j d j  ƒ ƒ | Sd } x8 | |  j | j  k rƒ | |  j | j  8} | d 7} qL W| d k rÅ | j |  j | d j | |  j | d j  ƒ ƒ n  | j |  j | j | | ƒ ƒ | S(   Niÿÿÿÿi    i   (   R   R(   R$   R   (   R	   R   R   R5   R/   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   ´   s     (   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   –   s   
	t   DelayAnimationc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s   
    Animation which performs no actions. Useful for lining up appended
    and parallel animations so that things run at the right times.
    g      ð?c         C   s.   t  |  _ t g  ƒ |  _ | |  _ t  |  _ d  S(   N(   R   R   R   R   R   R   (   R	   R   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   Ê   s    		c         C   s   i  S(   N(    (   R	   R   R   (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR   Ð   s    (   R   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyR6   Å   s   N(   R   t   objectR    R   R   R6   (    (    (    s4   /usr/lib/python2.7/site-packages/spyral/animation.pyt   <module>   s   `2/