writervideo = FFMpegWriter(fps=60) # anim.save(f, writer=writergif) animation_name_gif = "animation_test.gif" animation_name_video = "animation_test123.mp4" print( "Saving animation. Depending on the choise of 'save_count' this might take some time" ) print(f"Chosen 'save_count' = {_save_count}") # anim.save(animation_name, writer=writergif) anim.save(animation_name_video, writer=writervideo) print(f"Animation saved to {animation_name_video}") else: if plot_propterties: env_from_json.plot(ax1_1) scs_from_json.plot(ax1_1) for mn in mins_to_plot: mn.plot(ax1_1) mn.plot_traj_line(ax1_1) # mn.plot_vectors(env_from_json, ax1_1) mn.plot_force_traj_line(ax2_1) # mn.plot_xi_traj_line(ax2_2) # mins_to_plot[-1].plot_xi_traj_line(ax2_2) mins_to_plot[-1].plot_xi_traj_line(ax3_1) # ax2_1.legend(ncol=2, prop={'size': 9}) # ax3_1.legend(ncol=2, prop={'size': 9}) ax2_1.legend(ncol=1, prop={'size': 9}, handlelength=1,
return plt_pos_traj anim = FuncAnimation(fig, animate, init_func=init, interval=2, blit=False) if save_animation: animation_name = "animation.gif" print("Saving animation") anim.save(animation_name) print(f"Animation saved to {animation_name}") else: if plot_propterties: env.plot(ax1_1) scs.plot(ax1_1) for mn in beacons[ 1:]: #SCS is already plotted, using beacons instead of mins so that only landed mins are taken into account mn.plot(ax1_1) mn.plot_traj_line(ax1_1) mn.plot_vectors(env, ax1_1) mn.plot_force_traj_line(ax2_1) mn.plot_xi_traj_line(ax2_2) ax2_1.legend(ncol=2, prop={'size': 9}) else: env.plot(ax) scs.plot(ax) for j in range(len(beacons) - 1): # len(beacons)-1 so that it works when deploying unknown number of mins
# mins[1].pos = np.array([2*equal_dist,0]).reshape(2,) # mins[2].pos = np.array([0*equal_dist,1*equal_dist]).reshape(2,) # mins[3].pos = np.array([1*equal_dist,1*equal_dist]).reshape(2,) # mins[4].pos = np.array([2*equal_dist,1*equal_dist]).reshape(2,)#np.array([1.8,0.96]).reshape(2,)# # mins[5].pos = np.array([0*equal_dist,2*equal_dist]).reshape(2,)#np.array([3.2,0.9]).reshape(2,)# # mins[6].pos = np.array([1*equal_dist,2*equal_dist]).reshape(2,) # mins[7].pos = np.array([2*equal_dist,2*equal_dist]).reshape(2,) # for i in range(len(mins)): # mins[i].pos = np.array([i*equal_dist,]).reshape(2, ) fig = plt.figure(figsize=(5, 5)) ax_ref = fig.add_subplot(1, 1, 1) ax_ref.title.set_text(f"equal_dist = {equal_dist}") env.plot(ax_ref) scs.plot(ax_ref) beacons = np.array([scs], dtype=object) uniformity_list.append(scs.calc_uniformity() / len(beacons)) for mn in mins: mn.heading = 0 mn.state = MinState.LANDED mn.compute_neighbors(beacons) beacons = np.append(mn, beacons) uniformity_list.append( np.sum([beacon.calc_uniformity() for beacon in beacons]) / len(beacons)) delta_uniformity_list.append(uniformity_list[-1] - uniformity_list[-2]) # print(f"min {mn.ID} has {len(mn.neighbors)} neighs")