code: def iteration(self, dt):
      t = self._t
  
      t += 0.5 * dt
      # self.target[...] = np.array([np.sin(t),np.sin(2*t),np.cos(3*t)])*.1
  
      t += 0.5 * dt
      # self.predator[...] = np.array([np.sin(t),np.sin(2*t),np.cos(3*t)])*.2
  
      self.boids["position_2"] = self.boids["position_1"]
      self.boids["position_1"] = self.boids["position"]
      n = len(self.boids)
      P = self.boids["position"]
      V = self.boids["velocity"]
  
      # Cohesion: steer to move toward the average position of local
      # flockmates
      C = -(P - P.sum(axis=0) / n)
  
      # Alignment: steer towards the average heading of local flockmates
      A = -(V - V.sum(axis=0) / n)
  
      # Repulsion: steer to avoid crowding local flockmates
      D, idxs = cKDTree(P).query(P, 5)
      M = np.repeat(D < 0.05, 3, axis=1).reshape(n, 5, 3)
      Z = np.repeat(P, 5, axis=0).reshape(n, 5, 3)
      R = -((P[idxs] - Z) * M).sum(axis=1)
  
      # Target : Follow target
      T = self.target["position"] - P
  
      # Predator : Move away from predator
      dP = P - self.predator["position"]
      D = np.maximum(
          0,
          0.3 - np.sqrt(dP[:, 0] ** 2 + dP[:, 1] ** 2 + dP[:, 2] ** 2),
      )
      D = np.repeat(D, 3, axis=0).reshape(n, 3)
      dP *= D
  
      # self.boids['velocity'] += 0.0005*C + 0.01*A + 0.01*R +
      #                           0.0005*T + 0.0025*dP
      self.boids["velocity"] += (
          0.0005 * C + 0.01 * A + 0.01 * R + 0.0005 * T + 0.025 * dP
      )
      self.boids["position"] += self.boids["velocity"]
  
      self.vbo_position.set_data(self.particles["position"].copy())
  
      return t
  
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 7 for calling the Canvas obj's underlying member method code with example usage: obj.iteration(dt) and returns: t