Esempio n. 1
0
    for agent in listofagents:
        agent.draw(screen)
        agent.distance_based(dt)
        agent.neighbors = []

    # Draw the connected agents with a dashed line
    for edge in listofedges_and_distances:
        drawmisc.draw_dashed_line(screen, WHITE,
                                  (listofagents[edge[0]].pos[0],
                                   HEIGHT - listofagents[edge[0]].pos[1]),
                                  (listofagents[edge[1]].pos[0],
                                   HEIGHT - listofagents[edge[1]].pos[1]))

    clock.tick(fps)
    pygame.display.flip()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            endtime = pygame.time.get_ticks()
            pygame.quit()
            runsim = False

# Postprocessing

fig = pl.figure(0)
ax = fig.add_subplot(111)
for agent in listofagents:
    lp.plot_position(ax, agent)
ax.axis("equal")
pl.show()
time = 0

runsim = True
while (runsim):
    screen.fill(BLACK)
    agentsi.draw(screen)
    agentdi.draw(screen)
    agentuni.draw(screen)
    drawmisc.draw_dashed_line(screen, WHITE, (0, screen.get_height() - 0),
                              (100, screen.get_height() - 100))
    agentsi.step_dt(np.array([30, 2]), dt)
    agentdi.step_dt(np.array([0, 0]), dt)
    agentuni.step_dt(0, 0, dt)
    clock.tick(fps)
    pygame.display.flip()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            endtime = pygame.time.get_ticks()
            pygame.quit()
            runsim = False

# Postprocessing
fig = pl.figure(0)
ax = fig.add_subplot(111)
lp.plot_position(ax, agentsi)
lp.plot_position(ax, agentdi)
lp.plot_position(ax, agentuni)
ax.axis("equal")
pl.show()