def update(frame_num): nonlocal global_step nonlocal arrows global_step = frame_num robot.center = robot_positions[frame_num] for i, human in enumerate(humans): human.center = human_positions[frame_num][i] human_numbers[i].set_position((human.center[0] - x_offset, human.center[1] - y_offset)) for arrow in arrows: arrow.remove() arrows = [ patches.FancyArrowPatch(*orientation[frame_num], color=arrow_color, arrowstyle=arrow_style) for orientation in orientations ] for arrow in arrows: ax.add_artist(arrow) # if self.attention_weights is not None: # human.set_color(str(self.attention_weights[frame_num][i])) # attention_scores[i].set_text('human {}: {:.2f}'.format(i, self.attention_weights[frame_num][i])) time.set_text('Time: {:.2f}'.format(frame_num * self.time_step))
def animate(i): # according to number of savings time.set_text("time={}".format(i+1)) # agent for enum,ag in enumerate(trial.agents): # agent body agent_loc = Point(ag.data.x[i],ag.data.y[i]) agent_body = agent_loc.buffer(ag.data.r) agents[enum].set_data(*agent_body.exterior.xy) # trajectory trajs[enum].set_data(ag.data.x[:i+1],ag.data.y[:i+1]) # ir sensors ix = [ir for ir in ag.data.irs[i] if ir] for n_ir,ir in enumerate(ix): irs[enum][n_ir].set_data(*ir.exterior.xy) # feeding areas fx = ag.data.x[i] + (ag.data.r+ag.data.f_range/2)*np.sin(ag.data.o[i]) fy = ag.data.y[i] + (ag.data.r+ag.data.f_range/2)*np.cos(ag.data.o[i]) floc = Point(fx,fy) f_area = floc.buffer(ag.data.f_range/2) fas[enum].set_data(*f_area.exterior.xy) # same tuple for all irs of all agents all_irs = [ir for irx in irs for ir in irx] return tuple(agents),tuple(trajs),tuple(all_irs),tuple(fas)
def animate(i): # i: from number of savings in trial time.set_text("time={}".format(i)) # at: adjusted i for savings from agents' states at = int(i / evaluation.dt) # main centroid and triangle centroid.set_data(best_trial.triangles[i].centroid.xy) ags.set_data(*best_trial.triangles[i].exterior.xy) # remaining centroids (can be shorter) if i < len(rm_trials[0].triangles): cent2.set_data(rm_trials[0].triangles[i].centroid.xy) if i < len(rm_trials[1].triangles): cent3.set_data(rm_trials[1].triangles[i].centroid.xy) if i < len(rm_trials[2].triangles): cent4.set_data(rm_trials[2].triangles[i].centroid.xy) if i < len(rm_trials[3].triangles): cent5.set_data(rm_trials[3].triangles[i].centroid.xy) # ax1 agents for enum, ag in enumerate(best_trial.agents): # agent body agents[enum].set_data(*ag.data.body[at].exterior.xy) # trajectories trajs[enum].set_data(ag.data.x[:at], ag.data.y[:at]) # sensors ag_irs = [ir for ir in ag.data.irs[at] if ir] for n_ir, ir in enumerate(ag_irs): irs[enum][n_ir].set_data(*ir.xy) all_irs = [ir for irx in irs for ir in irx] # time mark for ax6 tbar.set_data([i, i], [0, 1]) #import pdb; pdb.set_trace() return centroid, ags, traj, tuple(agents) + tuple(all_irs)
def update(frame_num): nonlocal global_step global_step = frame_num robot.center = robot_positions[frame_num] for i, obstacle in enumerate(obstacles): obstacle.center = obstacle_positions[frame_num][i] obstacle_numbers[i].set_position((obstacle.center[0] - x_offset, obstacle.center[1] - y_offset)) time.set_text('Time: {:.2f}'.format(frame_num * self.time_step))
def update(frame_num): nonlocal global_step nonlocal arrows global_step = frame_num robot.center = robot_positions[frame_num] for i, human in enumerate(humans): human.center = human_positions[frame_num][i] human_numbers[i].set_position((human.center[0] - x_offset, human.center[1] - y_offset)) for arrow in arrows: arrow.remove() arrows = [ patches.FancyArrowPatch(*orientation[frame_num], color=arrow_color, arrowstyle=arrow_style) for orientation in orientations ] for arrow in arrows: ax.add_artist(arrow) if self.attention_weights is not None: human.set_color( str(self.attention_weights[frame_num][i])) attention_scores[i].set_text('human {}: {:.2f}'.format( i, self.attention_weights[frame_num][i])) # # print("agents_future_circles", agents_future_circles) # for i, circles in enumerate(agents_future_circles): # print("i", i, " cirle", circles) # for j, circle in enumerate(circles): # # print("j", j) # # print("agents_future_circles", agents_future_positions[0][j]) # # for k in range(len(agents_future_positions[0][j])): # # circle.center = [agents_future_positions[0][i][j], agents_future_positions[1][i][j]] # print("circle", circle.center) time.set_text('Time: {:.2f}'.format(frame_num * self.time_step))
def update(i, x, y, scat, d_t, time, Acc_fac): scat.set_offsets(np.vstack((x[Acc_fac * i, :], y[Acc_fac * i, :])).T) t = mth.floor(Acc_fac * d_t * i) time.set_text('Time = {}s'.format(t)) return scat, time,