Пример #1
0
    def spawn(self, num_units):
        for u in self.world.units:
            if u is not self.agent and u.position.distance_to(u.goal) < 1:
                self.world.remove_unit(u)

        for i in xrange(num_units):
            u = Stubborn()

            u.position = Vec2d(
                self.world.size[0] - u.radius - 1,
                random.randrange(u.radius, self.world.size[1] - u.radius)
            )

            while u.position.distance_to(self.agent.goal) < 5 * self.agent.radius:
                u.position = Vec2d(
                    self.world.size[0] - u.radius - 1,
                    random.randrange(u.radius, self.world.size[1] - u.radius)
                )

            u.goal = Vec2d(
                u.radius + 1,
                random.randrange(u.radius, self.world.size[1] - u.radius)
            )
            u.angle = (u.goal - u.position).angle()

            self.world.add_unit(u)
Пример #2
0
    def init(self):
        self.agent.position = Vec2d(200, 200)
        self.agent.goal = Vec2d(400, 200)
        self.agent.angle = 0

        u = Stubborn()
        u.position = Vec2d(300, 100)
        u.goal = Vec2d(300, 300)
        u.angle = math.pi / 2

        self.world.add_unit(u)
Пример #3
0
    def spawn(self, num_units):
        for u in self.world.units:
            if u is not self.agent and u.position.distance_to(u.goal) <= u.radius:
                self.world.remove_unit(u)
                avg_groundspeed = u.travel_length / (self.world._time - u.spawn_time)
                self.world.avg_groundspeed_list.append(avg_groundspeed)
                self.world.collision_list.append(u.collisions)
                #print ["Pedestrian Speed:", avg_groundspeed]
                #print ["Number of collisions:", u.collisions]

        for i in xrange(num_units):
            u = Stubborn()

            if random.random() < 0.5:  # coin toss
                # "horizontal" movement
                p1 = Vec2d(u.radius + 1, self.random_ypos(u))
                p2 = Vec2d(
                    self.world.size[0] - u.radius - 1,
                    self.random_ypos(u)
                )
            else:
                # "vertical" movement
                p1 = Vec2d(self.random_xpos(u), u.radius + 1)
                p2 = Vec2d(
                    self.random_xpos(u),
                    self.world.size[1] - u.radius - 1
                )

            if random.random() < 0.5:  # coin toss
                u.position = p1
                u.goal = p2
                u.angle = (p2 - p1).angle()
            else:
                u.position = p2
                u.goal = p1
                u.angle = (p1 - p2).angle()

            travel = u.goal - u.position
            u.travel_length = travel.length()
            u.spawn_time = self.world._time
            self.world.add_unit(u)