Exemplo n.º 1
0
def setup(n, width=800, height=600):

    world = pyafai.World2D(width, height)
    sim = simcx.PyafaiSimulator(world)
    vis = simcx.PyafaiVisual(sim)
    display = simcx.Display(width, height, caption="Random Walkers")

    display.add_simulator(sim)
    display.add_visual(vis)

    # Create agents
    x = np.random.randint(10, width - 10, n)
    y = np.random.randint(10, height - 10, n)
    speed = np.random.randint(50, 100, n)
    angle = np.random.randint(0, 359, n)
    for i in range(n):
        ag = RandomWalker(x[i], y[i], speed[i], angle[i],
                          ('c3B',
                           (random.randint(0, 255), random.randint(
                               0, 255), random.randint(0, 255))), 5)
        world.add_agent(ag)
Exemplo n.º 2
0
        shape = shapes.Pointer(10, color=color)
        obj.add_shape(shape)
        obj.velocity = vel
        self.body = obj
        self._last_think = 0.0

    def _think(self, delta):
        self._last_think += delta
        if self._last_think >= 0.2:
            self._last_think = 0
            rotate = random.choice((-180,0,180))
            self.body.ang_velocity = rotate

        return []

if __name__ == '__main__':
    world = pyafai.World2D(WORLD_WIDTH, WORLD_HEIGHT)
    display = pyafai.Display(world)

    for i in range(30):
        walker = RandomWalker(random.randint(10, WORLD_WIDTH-10),
                              random.randint(10, WORLD_HEIGHT-10),
                              random.randint(50,200),
                              ('c3B', (random.randint(0,255),
                                    random.randint(0,255),
                                    random.randint(0,255))))
        walker.body.angle = random.randint(0,359)
        world.add_agent(walker)

    pyafai.run()
Exemplo n.º 3
0
class BouncerObject(objects.SimplePhysicsObject):
    def __init__(self, w, h, x=0, y=0, angle=0):
        super(BouncerObject, self).__init__(x, y, angle)

        self._w = w
        self._h = h

    def update(self, delta):
        super(BouncerObject, self).update(delta)

        if self.x > self._w or self.x < 0:
            self.angle = 180 - self.angle

        if self.y > self._h or self.y < 0:
            self.angle = -self.angle


if __name__ == '__main__':
    world = pyafai.World2D()
    display = pyafai.Display(world)

    obj = BouncerObject(world.width, world.height, 200, 200)
    shape = shapes.Circle(5)
    obj.add_shape(shape)
    world.add_object(obj)
    obj.velocity = 300
    obj.angle = 30

    pyafai.run()