code: def __init__(self):
      app.Canvas.__init__(self, keys="interactive")
  
      ps = self.pixel_scale
  
      # Create boids
      n = 1000
      size_type = ("size", "f4", 1 * ps) if ps > 1 else ("size", "f4")
      self.particles = np.zeros(
          2 + n,
          [
              ("position", "f4", 3),
              ("position_1", "f4", 3),
              ("position_2", "f4", 3),
              ("velocity", "f4", 3),
              ("color", "f4", 4),
              size_type,
          ],
      )
      self.boids = self.particles[2:]
      self.target = self.particles[0]
      self.predator = self.particles[1]
  
      self.boids["position"] = np.random.uniform(-0.25, +0.25, (n, 3))
      self.boids["velocity"] = np.random.uniform(-0.00, +0.00, (n, 3))
      self.boids["size"] = 4 * ps
      self.boids["color"] = 1, 1, 1, 1
  
      self.target["size"] = 16 * ps
      self.target["color"][:] = 1, 1, 0, 1
      self.predator["size"] = 16 * ps
      self.predator["color"][:] = 1, 0, 0, 1
      self.target["position"][:] = 0.25, 0.0, 0
  
      # Time
      self._t = time.time()
      self._pos = 0.0, 0.0
      self._button = None
  
      width, height = self.physical_size
      gloo.set_viewport(0, 0, width, height)
  
      # Create program
      self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
  
      # Create vertex buffers
      self.vbo_position = gloo.VertexBuffer(
          self.particles["position"].copy()
      )
      self.vbo_color = gloo.VertexBuffer(self.particles["color"].copy())
      self.vbo_size = gloo.VertexBuffer(self.particles["size"].copy())
  
      # Bind vertex buffers
      self.program["color"] = self.vbo_color
      self.program["size"] = self.vbo_size
      self.program["position"] = self.vbo_position
  
      gloo.set_state(
          clear_color=(0, 0, 0, 1),
          blend=True,
          blend_func=("src_alpha", "one"),
      )
  
      self._timer = app.Timer("auto", connect=self.update, start=True)
  
      self.show()
  
file_path: vispy/examples/demo/gloo/boids.py
imports: import time
  import numpy
  from scipy.spatial import cKDTree
  from vispy import gloo
  from vispy import app
label_desc: Use image node_id 1 to create a new Canvas object from inherited base classes: app with example: obj = Canvas()