Example #1
0
 def updateAlignment(self, mates):
     """Alignment: Steer towards the average heading of local flockmates."""
     #mates = self.getVisibleMates(mates, self.alignment_perception)
     if len(mates) == 0:
         return Vector.null()
     v = Vector.average([m.velocity for m in mates])
     v.norm = self.max_velocity
     v -= self.velocity
     v.limit(self.max_acceleration)
     return v
Example #2
0
 def updateCohesion(self, mates):
     """Cohesion: steer to move toward the average position of local
     flockmates."""
     #mates = self.getVisibleMates(mates, self.cohesion_perception)
     if len(mates) == 0:
         return Vector.null()
     p = Vector.average([m.position for m in mates])
     v = p - self.position
     v.norm = self.max_velocity
     v -= self.velocity
     v.limit(self.max_acceleration)
     return v
Example #3
0
 def updateSeparation(self, mates):
     """Separation: Avoid crowding local flockmates."""
     #mates = self.getVisibleMates(mates, self.separation_perception)
     if len(mates) == 0:
         return Vector.null()
     vs = []
     for mate in mates:
         v = self.position - mate.position
         v.norm = 1 / v.norm
         vs.append(v)
     v = Vector.average(vs)
     v.norm = self.max_velocity
     v -= self.velocity
     v.limit(self.max_acceleration)
     return v
Example #4
0
 def getAcceleration(self):
     """Return the acceleration of the material form."""
     v = Vector.average([point.acceleration for point in self.points])
     v.color = mycolors.RED
     return v
Example #5
0
 def getVelocity(self):
     """Return the velocity of the center of the material form."""
     v = Vector.average([point.velocity for point in self.points])
     v.color = mycolors.BLUE
     return v
Example #6
0
 def getPosition(self):
     """Return the position of the center of the material form."""
     v = Vector.average([point.position for point in self.points])
     v.color = mycolors.GREEN
     return v