3030
3131
3232class Pad (object ):
33- def __init__ (self , disp ,x , y , type = 'l' ):
33+ def __init__ (self , disp , x , y , type = 'l' ):
3434 self .disp = disp
3535 self .x = x
3636 self .y = y
@@ -49,7 +49,7 @@ def __init__(self, disp,x,y,type='l'):
4949 self .signy = - 1.0
5050
5151 def contains (self , loc ):
52- return self .disp .get_bbox ().contains (loc .x ,loc .y )
52+ return self .disp .get_bbox ().contains (loc .x , loc .y )
5353
5454
5555class Puck (object ):
@@ -59,7 +59,7 @@ def __init__(self, disp, pad, field):
5959 self .field = field
6060 self ._reset (pad )
6161
62- def _reset (self ,pad ):
62+ def _reset (self , pad ):
6363 self .x = pad .x + pad .xoffset
6464 if pad .y < 0 :
6565 self .y = pad .y + pad .yoffset
@@ -71,7 +71,7 @@ def _reset(self,pad):
7171 self ._slower ()
7272 self ._slower ()
7373
74- def update (self ,pads ):
74+ def update (self , pads ):
7575 self .x += self .vx
7676 self .y += self .vy
7777 for pad in pads :
@@ -124,17 +124,17 @@ def __init__(self, ax):
124124 padAx = padBx = .50
125125 padAy = padBy = .30
126126 padBx += 6.3
127- pA , = self .ax .barh (padAy ,.2 , height = .3 ,color = 'k' , alpha = .5 , edgecolor = 'b' ,lw = 2 ,label = "Player B" , animated = True )
128- pB , = self .ax .barh (padBy ,.2 , height = .3 , left = padBx , color = 'k' ,alpha = .5 , edgecolor = 'r' ,lw = 2 ,label = "Player A" ,animated = True )
127+ pA , = self .ax .barh (padAy , .2 , height = .3 , color = 'k' , alpha = .5 , edgecolor = 'b' , lw = 2 , label = "Player B" , animated = True )
128+ pB , = self .ax .barh (padBy , .2 , height = .3 , left = padBx , color = 'k' , alpha = .5 , edgecolor = 'r' , lw = 2 , label = "Player A" , animated = True )
129129
130130 # distractors
131- self .x = np .arange (0 ,2.22 * np .pi ,0.01 )
132- self .line , = self .ax .plot (self .x , np .sin (self .x ),"r" , animated = True , lw = 4 )
133- self .line2 , = self .ax .plot (self .x , np .cos (self .x ),"g" , animated = True , lw = 4 )
134- self .line3 , = self .ax .plot (self .x , np .cos (self .x ),"g" , animated = True , lw = 4 )
135- self .line4 , = self .ax .plot (self .x , np .cos (self .x ),"r" , animated = True , lw = 4 )
136- self .centerline ,= self .ax .plot ([3.5 ,3.5 ], [1 ,- 1 ],'k' ,alpha = .5 , animated = True , lw = 8 )
137- self .puckdisp = self .ax .scatter ([1 ],[1 ],label = '_nolegend_' , s = 200 ,c = 'g' ,alpha = .9 ,animated = True )
131+ self .x = np .arange (0 , 2.22 * np .pi , 0.01 )
132+ self .line , = self .ax .plot (self .x , np .sin (self .x ), "r" , animated = True , lw = 4 )
133+ self .line2 , = self .ax .plot (self .x , np .cos (self .x ), "g" , animated = True , lw = 4 )
134+ self .line3 , = self .ax .plot (self .x , np .cos (self .x ), "g" , animated = True , lw = 4 )
135+ self .line4 , = self .ax .plot (self .x , np .cos (self .x ), "r" , animated = True , lw = 4 )
136+ self .centerline , = self .ax .plot ([3.5 , 3.5 ], [1 , - 1 ], 'k' , alpha = .5 , animated = True , lw = 8 )
137+ self .puckdisp = self .ax .scatter ([1 ], [1 ], label = '_nolegend_' , s = 200 , c = 'g' , alpha = .9 , animated = True )
138138
139139 self .canvas = self .ax .figure .canvas
140140 self .background = None
@@ -145,15 +145,15 @@ def __init__(self, ax):
145145 self .inst = True # show instructions from the beginning
146146 self .background = None
147147 self .pads = []
148- self .pads .append (Pad (pA ,0 , padAy ))
149- self .pads .append (Pad (pB ,padBx ,padBy ,'r' ))
148+ self .pads .append (Pad (pA , 0 , padAy ))
149+ self .pads .append (Pad (pB , padBx , padBy , 'r' ))
150150 self .pucks = []
151- self .i = self .ax .annotate (instructions ,(.5 ,0.5 ),
151+ self .i = self .ax .annotate (instructions , (.5 , 0.5 ),
152152 name = 'monospace' ,
153153 verticalalignment = 'center' ,
154154 horizontalalignment = 'center' ,
155155 multialignment = 'left' ,
156- textcoords = 'axes fraction' ,animated = True )
156+ textcoords = 'axes fraction' , animated = True )
157157 self .canvas .mpl_connect ('key_press_event' , self .key_press )
158158
159159 def draw (self , evt ):
@@ -196,12 +196,12 @@ def draw(self, evt):
196196 self .leg = self .ax .get_legend ()
197197 #self.leg.draw_frame(False) #don't draw the legend border
198198 self .leg .get_frame ().set_alpha (.2 )
199- plt .setp (self .leg .get_texts (),fontweight = 'bold' ,fontsize = 'xx-large' )
199+ plt .setp (self .leg .get_texts (), fontweight = 'bold' , fontsize = 'xx-large' )
200200 self .leg .get_frame ().set_facecolor ('0.2' )
201201 self .background = None
202202 self .ax .figure .canvas .draw ()
203203 return True
204- puck .disp .set_offsets ([puck .x ,puck .y ])
204+ puck .disp .set_offsets ([puck .x , puck .y ])
205205 self .ax .draw_artist (puck .disp )
206206
207207 # just redraw the axes rectangle
@@ -215,7 +215,7 @@ def draw(self, evt):
215215 self .cnt += 1
216216 return True
217217
218- def key_press (self ,event ):
218+ def key_press (self , event ):
219219 if event .key == '3' :
220220 self .res *= 5.0
221221 if event .key == '4' :
@@ -240,7 +240,7 @@ def key_press(self,event):
240240 self .pads [1 ].y = - 1
241241
242242 if event .key == 'a' :
243- self .pucks .append (Puck (self .puckdisp ,self .pads [randint (2 )],self .ax .bbox ))
243+ self .pucks .append (Puck (self .puckdisp , self .pads [randint (2 )], self .ax .bbox ))
244244 if event .key == 'A' and len (self .pucks ):
245245 self .pucks .pop ()
246246 if event .key == ' ' and len (self .pucks ):
0 commit comments