| 1 |
|
| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
import sys |
| 14 |
|
| 15 |
import pyglet |
| 16 |
|
| 17 |
if len(sys.argv) > 1: |
| 18 |
|
| 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 |
|
| 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 |
|
| 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() |