Revision: 7507
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7507&view=rev
Author: ryanmay
Date: 2009-08-20 06:44:26 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Fix problem with call to draw in pong demo. Also make draw use 10 ms timers
instead of drawing on idle so that it doesn't peg the CPU.
Modified Paths:
--------------
trunk/matplotlib/examples/event_handling/pipong.py
trunk/matplotlib/examples/event_handling/pong_gtk.py
trunk/matplotlib/examples/event_handling/pong_qt.py
Modified: trunk/matplotlib/examples/event_handling/pipong.py
===================================================================
--- trunk/matplotlib/examples/event_handling/pipong.py 2009-08-19 07:56:33 UTC
(rev 7506)
+++ trunk/matplotlib/examples/event_handling/pipong.py 2009-08-20 06:44:26 UTC
(rev 7507)
@@ -12,17 +12,17 @@
'e' up 'i'
'd' down 'k'
-press 't' -- close these instructions
+press 't' -- close these instructions
(animation will be much faster)
-press 'a' -- add a puck
-press 'A' -- remove a puck
-press '1' -- slow down all pucks
-press '2' -- speed up all pucks
-press '3' -- slow down distractors
-press '4' -- speed up distractors
+press 'a' -- add a puck
+press 'A' -- remove a puck
+press '1' -- slow down all pucks
+press '2' -- speed up all pucks
+press '3' -- slow down distractors
+press '4' -- speed up distractors
press ' ' -- reset the first puck
-press 'n' -- toggle distractors on/off
-press 'g' -- toggle the game on/off
+press 'n' -- toggle distractors on/off
+press 'g' -- toggle the game on/off
"""
@@ -56,7 +56,7 @@
def _reset(self,pad):
self.x = pad.x + pad.xoffset
if pad.y < 0:
- self.y = pad.y + pad.yoffset
+ self.y = pad.y + pad.yoffset
else:
self.y = pad.y - pad.yoffset
self.vx = pad.x - self.x
@@ -84,7 +84,7 @@
self._reset(pads[1])
return True
if self.y < -1+fudge or self.y > 1-fudge:
- self.vy *= -1.0
+ self.vy *= -1.0
# add some randomness, just to make it interesting
self.vy -= (randn()/300.0 + 1/300.0) * np.sign(self.vy)
self._speedlimit()
@@ -106,7 +106,7 @@
if self.vy < -self.vmax:
self.vy = -self.vmax
-class Game(object):
+class Game(object):
def __init__(self, ax):
# create the initial line
@@ -137,7 +137,7 @@
self.pads = []
self.pads.append( Pad(pA,0,padAy))
self.pads.append( Pad(pB,padBx,padBy,'r'))
- self.pucks =[]
+ self.pucks =[]
self.i = self.ax.annotate(instructions,(.5,0.5),
name='monospace',
verticalalignment='center',
@@ -180,8 +180,8 @@
for puck in self.pucks:
if puck.update(self.pads):
# we only get here if someone scored
- self.pads[0].disp.set_label(" "+
str(self.pads[0].score))
- self.pads[1].disp.set_label(" "+
str(self.pads[1].score))
+ self.pads[0].disp.set_label(" "+ str(self.pads[0].score))
+ self.pads[1].disp.set_label(" "+ str(self.pads[1].score))
self.ax.legend(loc='center')
self.leg = self.ax.get_legend()
#self.leg.draw_frame(False) #don't draw the legend border
@@ -189,7 +189,7 @@
plt.setp(self.leg.get_texts(),fontweight='bold',fontsize='xx-large')
self.leg.get_frame().set_facecolor('0.2')
self.background = None
- self.ax.draw()
+ self.ax.figure.canvas.draw()
return True
puck.disp.set_offsets([puck.x,puck.y])
self.ax.draw_artist(puck.disp)
@@ -229,7 +229,7 @@
self.pads[1].y -= .1
if self.pads[1].y < -1:
self.pads[1].y = -1
-
+
if event.key == 'a':
self.pucks.append(Puck(self.puckdisp,self.pads[randint(2)],self.ax.bbox))
if event.key == 'A' and len(self.pucks):
@@ -242,7 +242,7 @@
if event.key == '2':
for p in self.pucks:
p._faster()
-
+
if event.key == 'n':
self.distract = not self.distract
@@ -254,4 +254,4 @@
self.inst = not self.inst
self.i.set_visible(self.i.get_visible())
if event.key == 'q':
- plt.close()
+ plt.close()
Modified: trunk/matplotlib/examples/event_handling/pong_gtk.py
===================================================================
--- trunk/matplotlib/examples/event_handling/pong_gtk.py 2009-08-19
07:56:33 UTC (rev 7506)
+++ trunk/matplotlib/examples/event_handling/pong_gtk.py 2009-08-20
06:44:26 UTC (rev 7507)
@@ -12,7 +12,7 @@
import numpy as np
import matplotlib.pyplot as plt
-import pipong
+import pipong
from numpy.random import randn, randint
@@ -22,7 +22,8 @@
def start_anim(event):
- gobject.idle_add(animation.draw,animation)
+# gobject.idle_add(animation.draw,animation)
+ gobject.timeout_add(10,animation.draw,animation)
canvas.mpl_disconnect(start_anim.cid)
animation = pipong.Game(ax)
Modified: trunk/matplotlib/examples/event_handling/pong_qt.py
===================================================================
--- trunk/matplotlib/examples/event_handling/pong_qt.py 2009-08-19 07:56:33 UTC
(rev 7506)
+++ trunk/matplotlib/examples/event_handling/pong_qt.py 2009-08-20 06:44:26 UTC
(rev 7507)
@@ -18,7 +18,7 @@
import matplotlib.pyplot as plt
import numpy as np
import time
-import pipong
+import pipong
from numpy.random import randn, randint
class BlitQT(QObject):
@@ -36,7 +36,7 @@
app = BlitQT()
# for profiling
app.tstart = time.time()
-app.startTimer(0)
+app.startTimer(10)
plt.show()
print 'FPS:' , app.animation.cnt/(time.time()-app.tstart)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins