(self)
| 192 | self.canvas.mpl_connect('key_press_event', self.on_key_press) |
| 193 | |
| 194 | def draw(self): |
| 195 | draw_artist = self.ax.draw_artist |
| 196 | if self.background is None: |
| 197 | self.background = self.canvas.copy_from_bbox(self.ax.bbox) |
| 198 | |
| 199 | # restore the clean slate background |
| 200 | self.canvas.restore_region(self.background) |
| 201 | |
| 202 | # show the distractors |
| 203 | if self.distract: |
| 204 | self.line.set_ydata(np.sin(self.x + self.cnt/self.res)) |
| 205 | self.line2.set_ydata(np.cos(self.x - self.cnt/self.res)) |
| 206 | self.line3.set_ydata(np.tan(self.x + self.cnt/self.res)) |
| 207 | self.line4.set_ydata(np.tan(self.x - self.cnt/self.res)) |
| 208 | draw_artist(self.line) |
| 209 | draw_artist(self.line2) |
| 210 | draw_artist(self.line3) |
| 211 | draw_artist(self.line4) |
| 212 | |
| 213 | # pucks and pads |
| 214 | if self.on: |
| 215 | self.ax.draw_artist(self.centerline) |
| 216 | for pad in self.pads: |
| 217 | pad.disp.set_y(pad.y) |
| 218 | pad.disp.set_x(pad.x) |
| 219 | self.ax.draw_artist(pad.disp) |
| 220 | |
| 221 | for puck in self.pucks: |
| 222 | if puck.update(self.pads): |
| 223 | # we only get here if someone scored |
| 224 | self.pads[0].disp.set_label(f" {self.pads[0].score}") |
| 225 | self.pads[1].disp.set_label(f" {self.pads[1].score}") |
| 226 | self.ax.legend(loc='center', framealpha=.2, |
| 227 | facecolor='0.5', |
| 228 | prop=FontProperties(size='xx-large', |
| 229 | weight='bold')) |
| 230 | |
| 231 | self.background = None |
| 232 | self.ax.figure.canvas.draw_idle() |
| 233 | return |
| 234 | puck.disp.set_offsets([[puck.x, puck.y]]) |
| 235 | self.ax.draw_artist(puck.disp) |
| 236 | |
| 237 | # just redraw the Axes rectangle |
| 238 | self.canvas.blit(self.ax.bbox) |
| 239 | self.canvas.flush_events() |
| 240 | if self.cnt == 50000: |
| 241 | # just so we don't get carried away |
| 242 | print("...and you've been playing for too long!!!") |
| 243 | plt.close() |
| 244 | |
| 245 | self.cnt += 1 |
| 246 | |
| 247 | def on_key_press(self, event): |
| 248 | if event.key == '3': |
no test coverage detected