Animations

You can animate arbitrary objects using the function wasabi2d.animate(). For example, to move a primitive from its current position on the screen to the position (100, 100):

animate(alien, pos=(100, 100))
animate(object, tween='linear', duration=1, on_finished=None, **targets)

Animate the attributes on object from their current value to that specified in the targets keywords.

Parameters
  • tween – The type of tweening to use.

  • duration – The duration of the animation, in seconds.

  • on_finished – Function called when the animation finishes.

  • targets – The target values for the attributes to animate.

The tween argument can be one of the following:

Name

Description

Plot (x = t, y = tween(t))

linear

Animate at a constant speed from start to finish

_images/linear.png

accelerate

Start slower and accelerate to finish

_images/accelerate.png

decelerate

Start fast and decelerate to finish

_images/decelerate.png

accel_decel

Accelerate to mid point and decelerate to finish

_images/accel_decel.png

in_elastic

Give a little wobble at the end

_images/in_elastic.png

out_elastic

Have a little wobble at the start

_images/out_elastic.png

in_out_elastic

Have a wobble at both ends

_images/in_out_elastic.png

bounce_end

Accelerate to the finish and bounce there

_images/bounce_end.png

bounce_start

Bounce at the start

_images/bounce_start.png

bounce_start_end

Bounce at both ends

_images/bounce_start_end.png

The animate() function returns an Animation instance:

class Animation
stop(complete=False)

Stop the animation, optionally completing the transition to the final property values.

Parameters

complete – Set the animated attribute to the target value.

running

This will be True if the animation is running. It will be False when the duration has run or the stop() method was called before then.

on_finished

You may set this attribute to a function which will be called when the animation duration runs out. The on_finished argument to animate() also sets this attribute. It is not called when stop() is called. This function takes no arguments.