File: animation.py

package info (click to toggle)
pyglet 2.0.17%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,560 kB
  • sloc: python: 80,579; xml: 50,988; ansic: 171; makefile: 146
file content (44 lines) | stat: -rwxr-xr-x 1,027 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""Load and display a GIF animation.

Usage::

    animation.py [<filename>]

If the filename is omitted, a sample animation is loaded
"""

__docformat__ = 'restructuredtext'
__version__ = '$Id$'

# The dinosaur.gif file packaged alongside this script is in the public
# domain, it was obtained from http://www.gifanimations.com/.

import sys

import pyglet

if len(sys.argv) > 1:
    # Load the animation from file path.
    animation = pyglet.image.load_animation(sys.argv[1])
    texture_bin = pyglet.image.atlas.TextureBin()
    animation.add_to_texture_bin(texture_bin)
else:
    # Load animation from resource (this script's directory).
    animation = pyglet.resource.animation('dinosaur.gif')

window = pyglet.window.Window(width=animation.get_max_width(), height=animation.get_max_height())
sprite = pyglet.sprite.Sprite(animation)


# Set window background color to white.
pyglet.gl.glClearColor(1, 1, 1, 1)


@window.event
def on_draw():
    window.clear()
    sprite.draw()


pyglet.app.run()