저는 C 프로그램을 파이썬으로 '번역'하고 있습니다. 그것은 y 축상의 입자의 감쇠 된 단순 조화 운동입니다. 애니메이션은 matplotlib의 FuncAnimation을 사용합니다. 입자의 경로가 정확하게 표현 될 수 있도록 모든 단계 (프레임)마다 작은 단계 크기 (dh)를 사용합니다. 작은 dh 문제는 단위 거리 당 프레임 수를 늘립니다. 작은 dh에 대해 애니메이션이 더 빠르게 (높은 fps) 진행되도록 초당 프레임을 늘리는 방법이 있습니까?FuncAnimation은 긴 애니메이션의 FPS를 증가 시킵니까?
그런데이 프로그램은 둘 이상의 입자를 사용하는 것과 같은 미래의 개선을 위해 2D 배열을 사용합니다. 그러나 모든 입자를 움직이게하는 방법을 아직 도입하지는 못했지만 이것이 문제는 아닙니다. 애니메이션 interval
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
#The bungee rope has to have a [k = 0.15] in order to do 5 oscillations
N = 1
dt = 0.1 #//size step
time = 8000
count =1;
b = 1;
k = 0.2;
m= 100;
# function to open an x-window
fig = plt.figure()
#define positions and velocities for each
x = np.zeros((N,time))
y = np.zeros((N,time))
vx = np.zeros((N,time))
vy = np.zeros((N,time))
#define variables for the plotting canvas
xmin = -5.0; xmax =5.0;
ymin = -80.0; ymax = 80.0;
ax = plt.axes(xlim= (xmin,xmax), ylim=(ymin,ymax),ylabel = 'Y Position')
(my_point,) = ax.plot([],[],'ro',ms=7) #stored var to make red circle (ro) point
#set initial position and velocity
x[:N,0] = 0; y[:N,0] = 75;
vx[:N,0] = 0; vy[:N,0] = 0.0;
for i in range(time-1):
#set path/function
for j in range(N):
a = (-k*y[j,i] - b*vy[j,i])/(m); #damped simple harmonic motion
vy[j,i+1] = vy[j,i] + a*dt #differential changes to velocity
y[j,i+1] = y[j,i] + dt*vy[j,i+1] #differential changes to distance
def get_step(n,x,y,point):
point.set_data(x[n],y[n])
mymovie = animation.FuncAnimation(fig,get_step,frames= time,\
fargs=(x[0,:],y[0,:],my_point), interval = 0)
plt.show()
print("For 5 oscillations k = %f\n" % k)