I have just checked in animation code into kaa.canvas.  Animation
methods are called "animators" and several have been coded:

      * size: scale the object by width, height, or both (for those
        objects that support resizing [basically canvas.Image and
        canvas.Movie]).  Relative (percentage) values allowed.
      * move: move the object to coordinates specified by left, top,
        right, bottom, hcenter, vcenter.  Relative (percentage) values
        allowed.
      * color: change the image's color; can also be used for fading
        (since alpha is considered color)
      * sequence: defines a sequence of transitions for any of the
        previous methods.  So you can have an object move to several
        points, or scale to certain specified sizes, etc.
      * throb: a subclass of SequenceAnimator with loop=True, and uses
        the "size" method, so an object has a "throb" effect (think of a
        pulsing heart).

Animators are initialized via the kaa.canvas.animate() function, or via
canvas.Object.animate() method (which is a convenience method).  These
functions return an Animator object on which you can call start() or
stop() explicitly, if you wish.  Animators will start automatically
unless deferred=True is specified.  Other valid kwargs are:

      * deferred: If true, animation will not begin until start() is
        called explicitly on the animator.  Otherwise it will begin as
        soon as instantiated.  (Default: False)
      * duration: specifies the duration in seconds for the animation.
      * bounce: if True, the animator will overshoot its target by some
        factor, and then animate back to the originally specified value.
        Gives a nice bounce effect.
      * bounce_factor: the amount by which to bounce (if bounce=True);
        defaults to 0.1
      * accelerate: if True, will accelerate to the end value.
      * decelerate: if True, will decelerate to the end value.
      * end_callback: a function to call when the animation is finished.

If accelerate is True, the current position is determined by an
exponential function.  If decelerate is true, the current position is
determined by a logarithmic function.  If both are False, it's linear.
I might look at other curves (like hyperbolic) that might yield more
pleasing motion.

Animators can be added arbitrarily to objects.  Only one animator of a
given type can exist for a given object, and new animators will replace
existing animators of that type for the given object.  For example, if
you animate an object to fade out, and then add a new animator to fade
the object in before the old one is done, the old animator will be
discarded.

Crossfading can be done simply by adding a color animator to object A
with a=0, and adding a color animator to object B with a=255:

        image1 = c.add_child(canvas.Image("image1.jpg"))
        image2 = c.add_child(canvas.Image("image2.jpg"))
        image2.set_color(a = 0)  # image2 is initialized to invisible.
        
        image1.animate("color", a = 0, duration = 0.3)
        image2.animate("color", a = 255, duration = 0.3)
        
This will cause a crossfade between image1 and image2 that completes in
0.3 seconds.

I have committed an example to kaa/canvas/test/animation.  It implements
a menu similar to what you see here:

   http://sault.org/mebox/images/mainmenu.png

When you move the arrow keys, the menu selector animates to the new
position, and gives a little bounce before it settles on the new menu
item.  Similarly, the image zooms and fades as you select new menu
items.  It is an effect that basically copies Windows Media Center,
because I have no creative talent.  But it looks very cool! :)

(The example in svn requires the trebuchet font, so if you don't have
it, just edit the code and change "trebuc" to something else.  Also if
you have a GL capable card, you can set use_gl = True to get smoother
performance.  [Assuming your evas is compiled with x11_gl.])

I'll add most of the above to the canvas docs tomorrow.

Cheers,
Jason.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to