Example #1
0
    def seperation(self, fish, minDistance):
        if len(fish) < 1:
            return Vector()

        distance = 0
        numClose = 0
        distsum = Vector()
        for boid in fish:
            distance = (self.pos - boid.pos).length()
            if distance < minDistance and distance != 0:
                numClose += 1
                distsum += (boid.pos - self.pos).divide(distance**2)

        if numClose == 0:
            return Vector()

        return (-distsum.divide(numClose)).normalize()
Example #2
0
    def allign(self, fish):
        if len(fish) < 1:
            return
        # calculate the average velocities of the other boids
        avg = Vector()
        count = 0
        for boid in fish:
            if (boid.pos - self.pos).length() < self.per:
                count += 1
                avg += boid.vel

        if count > 0:
            avg = avg.divide(count)
            # set our velocity towards the others
            return (avg).normalize()
        else:
            return Vector()
Example #3
0
    def cohesion(self, fish):
        if len(fish) < 1:
            return

        # calculate the average distances from the other boids
        com = Vector()
        count = 0
        for boid in fish:
            if boid.pos == self.pos:
                continue
            elif (boid.pos - self.pos).length() < self.per:
                com += (self.pos - boid.pos)
                count += 1
        if count > 0:
            com = com.divide(count)
            return -com.normalize()
        else:
            return Vector()