Debian Codegraph @

examples/programming_guide/animation.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """Load and display a GIF animation.
3
4 Usage::
5
6 animation.py [<filename>]
7
8 If the filename is omitted, a sample animation is loaded
9 """
10 # The dinosaur.gif file packaged alongside this script is in the public
11 # domain, it was obtained from http://www.gifanimations.com/.
12
13 import sys
14
15 import pyglet
16
17 if len(sys.argv) > 1:
18 # Load the animation from file path.
19 animation = pyglet.image.load_animation(sys.argv[1])
20 texture_bin = pyglet.image.atlas.TextureBin()
21 animation.add_to_texture_bin(texture_bin)
22 else:
23 # Load animation from resource (this script's directory).
24 animation = pyglet.resource.animation('dinosaur.gif')
25
26 window = pyglet.window.Window(width=animation.get_max_width(), height=animation.get_max_height())
27 sprite = pyglet.sprite.Sprite(animation)
28
29
30 # Set window background color to white.
31 pyglet.gl.glClearColor(1, 1, 1, 1)
32
33
34 @window.event
35 def on_draw():
36 window.clear()
37 sprite.draw()
38
39
40 pyglet.app.run()