File: pong_gtk.py

package info (click to toggle)
matplotlib 1.1.1~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 66,076 kB
  • sloc: python: 90,600; cpp: 69,891; objc: 5,231; ansic: 1,723; makefile: 171; sh: 7
file content (36 lines) | stat: -rw-r--r-- 825 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python

# For detailed comments on animation and the techniques used here, see
# the wiki entry
# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation
import time

import gtk, gobject

import matplotlib
matplotlib.use('GTKAgg')

import numpy as np
import matplotlib.pyplot as plt
import pipong
from numpy.random import randn, randint


fig = plt.figure()
ax = fig.add_subplot(111)
canvas = ax.figure.canvas


def start_anim(event):
#    gobject.idle_add(animation.draw,animation)
    gobject.timeout_add(10,animation.draw,animation)
    canvas.mpl_disconnect(start_anim.cid)

animation = pipong.Game(ax)
start_anim.cid = canvas.mpl_connect('draw_event', start_anim)


tstart = time.time()
plt.grid() # to ensure proper background restore
plt.show()
print 'FPS:' , animation.cnt/(time.time()-tstart)