Clutter Animation
#!/usr/bin/env python
#
# [SNIPPET_NAME: Clutter Animation]
# [SNIPPET_CATEGORIES: Clutter]
# [SNIPPET_DESCRIPTION: Shows clutter animations and how to respond to the completion of animations]
# [SNIPPET_AUTHOR: Andy Breiner <[email protected]>]
# [SNIPPET_LICENSE: GPL]
# [SNIPPET_DOCS: http://clutter-project.org/docs/pyclutter/stable/]
import clutter
class ClutterAnimation:
def __init__ (self):
# Create the stage, set the background to white,
# set the size to 400,400, set the title,
# finally when the user user clicks the x actually close the
# program
self.stage = clutter.Stage()
self.stage.set_color(clutter.color_from_string('White'))
self.stage.set_size(400, 400)
self.stage.set_title('Clutter Animation')
self.stage.connect("destroy",clutter.main_quit)
# Setup the image, set the anchor (by default, items are animated from
# the top left, by changing the anchor we animate from a
# different spot), next it sets the position of the image to be in
# the middle of the stage, and finally add it to the stage
self.image = clutter.texture_new_from_file("./jono.png")
self.image.set_anchor_point(self.image.get_width()/2,
self.image.get_height()/2)
self.image.set_position(self.stage.get_width()/2,
self.stage.get_height()/2)
self.stage.add(self.image)
# Create label and set its properties.
label = clutter.Text()
label.set_font_name('Mono 32')
label.set_text("Jono")
label.set_color(clutter.color_from_string("#000000DD"))
label.set_anchor_point(label.get_width()/2, label.get_height()/2)
label.set_position(0, 100)
self.stage.add(label)
# This creates an animation
# clutter.AnimationMode sets how to animate it
# clutter.LINEAR makes it be at the same speed throughout the
# animation, the 5000 is the duration
# finally we rotate along the y axis, z axis, and x-axis
lanimation = label.animate(clutter.AnimationMode(clutter.EASE_OUT_BOUNCE),
3000,
"x", self.stage.get_height() / 2.0)
# Tells the computer what to do when the animation is done
lanimation.connect("completed", self.next_animation)
#show the stage and start clutter
self.stage.show_all()
clutter.main()
def next_animation(self, data=None):
# for this animation we update the y value so it looks like it
# bounces
ianimation = self.image.animate(clutter.AnimationMode(clutter.LINEAR),
5000,
"rotation-angle-y", 500.0)
# Run program.
if __name__ == "__main__":
main = ClutterAnimation()