class_docstr: Helper to grab a series of screenshots from the current Canvas-like object.
code: def on_draw(self, _):
      if self._done:
          return  # Grab only once
      self._current_frame += 1
      if self._current_frame in self._frames_to_grab:
          self._frames_to_grab.remove(self._current_frame)
          if isinstance(self._canvas, SceneCanvas):
              im = self._canvas.render(alpha=True)
          else:
              im = _screenshot()
          self._collected_images.append(im)
      if (
          not self._frames_to_grab
          or self._current_frame > self._frames_to_grab[0]
      ):
          self._done = True
  
imports: from __future__ import annotations
  import os
  import time
  import shutil
  from vispy.io import imsave
  from vispy.gloo.util import _screenshot
  from vispy.scene import SceneCanvas
  from sphinx_gallery.scrapers import optipng, figure_rst
label_desc: Use image node_id 3 for calling the FrameGrabber obj's underlying member method code with example usage: obj.on_draw(_) without return types