30
30
31
31
32
32
class Pad (object ):
33
- def __init__ (self , disp ,x , y , type = 'l' ):
33
+ def __init__ (self , disp , x , y , type = 'l' ):
34
34
self .disp = disp
35
35
self .x = x
36
36
self .y = y
@@ -49,7 +49,7 @@ def __init__(self, disp,x,y,type='l'):
49
49
self .signy = - 1.0
50
50
51
51
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 )
53
53
54
54
55
55
class Puck (object ):
@@ -59,7 +59,7 @@ def __init__(self, disp, pad, field):
59
59
self .field = field
60
60
self ._reset (pad )
61
61
62
- def _reset (self ,pad ):
62
+ def _reset (self , pad ):
63
63
self .x = pad .x + pad .xoffset
64
64
if pad .y < 0 :
65
65
self .y = pad .y + pad .yoffset
@@ -71,7 +71,7 @@ def _reset(self,pad):
71
71
self ._slower ()
72
72
self ._slower ()
73
73
74
- def update (self ,pads ):
74
+ def update (self , pads ):
75
75
self .x += self .vx
76
76
self .y += self .vy
77
77
for pad in pads :
@@ -124,17 +124,17 @@ def __init__(self, ax):
124
124
padAx = padBx = .50
125
125
padAy = padBy = .30
126
126
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 )
129
129
130
130
# 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 )
138
138
139
139
self .canvas = self .ax .figure .canvas
140
140
self .background = None
@@ -145,15 +145,15 @@ def __init__(self, ax):
145
145
self .inst = True # show instructions from the beginning
146
146
self .background = None
147
147
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' ))
150
150
self .pucks = []
151
- self .i = self .ax .annotate (instructions ,(.5 ,0.5 ),
151
+ self .i = self .ax .annotate (instructions , (.5 , 0.5 ),
152
152
name = 'monospace' ,
153
153
verticalalignment = 'center' ,
154
154
horizontalalignment = 'center' ,
155
155
multialignment = 'left' ,
156
- textcoords = 'axes fraction' ,animated = True )
156
+ textcoords = 'axes fraction' , animated = True )
157
157
self .canvas .mpl_connect ('key_press_event' , self .key_press )
158
158
159
159
def draw (self , evt ):
@@ -196,12 +196,12 @@ def draw(self, evt):
196
196
self .leg = self .ax .get_legend ()
197
197
#self.leg.draw_frame(False) #don't draw the legend border
198
198
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' )
200
200
self .leg .get_frame ().set_facecolor ('0.2' )
201
201
self .background = None
202
202
self .ax .figure .canvas .draw ()
203
203
return True
204
- puck .disp .set_offsets ([puck .x ,puck .y ])
204
+ puck .disp .set_offsets ([puck .x , puck .y ])
205
205
self .ax .draw_artist (puck .disp )
206
206
207
207
# just redraw the axes rectangle
@@ -215,7 +215,7 @@ def draw(self, evt):
215
215
self .cnt += 1
216
216
return True
217
217
218
- def key_press (self ,event ):
218
+ def key_press (self , event ):
219
219
if event .key == '3' :
220
220
self .res *= 5.0
221
221
if event .key == '4' :
@@ -240,7 +240,7 @@ def key_press(self,event):
240
240
self .pads [1 ].y = - 1
241
241
242
242
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 ))
244
244
if event .key == 'A' and len (self .pucks ):
245
245
self .pucks .pop ()
246
246
if event .key == ' ' and len (self .pucks ):
0 commit comments