def make_animation(pos, filename, plt, AutoMinorLocator, step=100): anim = animation(filename) for i in tqdm(range(110, pos.size, step)): fig, ax = plt.subplots(1, 1, figsize=(10, 7)) ax.axhline(y=0, color='gray', alpha=0.5) ax.axhline(y=10, color='gray', alpha=0.5) ax.axvline(x=-5, color='gray', alpha=0.5) ax.axvline(x=5, color='gray', alpha=0.5) ax.xaxis.set_minor_locator(AutoMinorLocator()) ax.yaxis.set_minor_locator(AutoMinorLocator()) ax.tick_params(which='both', labelsize=17, direction='in', top=True, right=True) ax.tick_params(which='major', length=10, width=1) ax.tick_params(which='minor', length=5, width=1) ax.set_xlabel('$x$ [m]', fontsize=20) ax.set_ylabel('$y$ [m]', fontsize=20) ax.plot(pos[i - 100:i, 0], pos[i - 100:i, 1], 'k') anim.add_frame(fig) plt.close(fig) anim.close()
def load_and_animate_from_disk(datafile, animationName, fps, skip): state = load_C_output(datafile) anim = animation(animationName, fps=fps) for i, timestep in tqdm(enumerate(state), total=len(state)): if i % skip == 0: fig = plt.figure() plt.plot(timestep[:, 0], timestep[:, 1], 'o') anim.add_frame(fig) plt.close(fig) anim.close()
def animate_system(filename, state, fps=30, skip=1): anim = animation(filename, fps=fps) for i, y in tqdm(enumerate(state), total=state.shape[0]): if i % skip == 0: fig, ax = plot_system(y) ax.set_xlim(-15, 15) ax.set_ylim(-15, 15) anim.add_frame(fig) plt.close(fig) anim.close() del (anim)
def main(): figList = list() filename1 = 'TestAnimation.mp4' filename2 = 'TestAnimation_context.mp4' t = 100 N = 100 guass = np.random.normal(size=(t, 2, N)) anim = animation(filename1, fps=60) for coord in tqdm(guass): fig, ax = plt.subplots(1, 1, figsize=(10, 7)) ax.plot(coord[0], coord[1], 'o') anim.add_frame(fig) plt.close(fig) anim.close() with animation(filename2, fps=60) as anim: for coord in tqdm(guass): fig, ax = plt.subplots(1, 1, figsize=(10, 7)) ax.plot(coord[0], coord[1], 'o') anim.add_frame(fig) plt.close(fig)
v[0,0], v[0,-1], v[-1,0], v[-1,-1]=0, 0, 0, 0 # fixed coners else: v[0,0], v[0,-1], v[-1,0], v[-1,-1]=0, 0, 0 return np.array([v,a]) L, M, N = 2.0, 15, 15 # size, (M,N) particle array h, mass, damp = 0.01, 0.004, 0.01 # keep damp between [.01,.1] x, y = np.linspace(0,L,M), np.linspace(0,L,N) r, v = np.zeros((N,M,3)), np.zeros((N,M,3)) spring_k, spring_l = 50.0, x[1]-x[0] # spring const., relaxed length r[:,:, 0], r[:,:, 1] = np.meshgrid(x,y) # initialize pos Y, gvec = np.array([r, v]), np.array([0,0,-9.8]) # [v,a], g vector x, y, z = r[:,:,0], r[:,:,1], r[:,:,2] # mesh points fig = plt.figure(figsize=(20, 17)) ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z) t=0 anim = animation('FallingCloth.mp4') for t in tqdm(np.arange(0, 2, h)): Y = RK4(cloth, Y, 0, h) x, y, z = Y[0,:,:,0], Y[0,:,:,1], Y[0,:,:,2] fig = plt.figure(figsize=(20, 17)) ax = fig.add_subplot(111, projection='3d') ax.set_zlim(-1.3, 0) ax.plot_surface(x, y, z) anim.add_frame(fig) plt.close(fig) anim.close()