from math import *
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# frequence moyenne et ecart frequentiel
f0=5
deltaf=0.1

# bornes et constantes
Xmin=0
Xmax=80.0
NX=1001
c=2
dt=0.1
# discretisation axe des x
x=np.linspace(Xmin,Xmax,NX)

#initialisation de la figure
fig = plt.figure()
plt.xlim(Xmin,Xmax)
plt.ylim(-1,1)
plt.grid()

line,=plt.plot([],[])

# vitesse de phase type plasma
def vphi(f) :
    return c/(sqrt(1-(f0/1.15)**2/f**2))

# fonction d'onde, paquet d'onde gaussien
def onde(x,t) :
    ond=0
    for i in range(1,200) :
        f=f0-5*deltaf+i*5*deltaf/50
        ond=ond+5/100*np.exp(-((f-f0)/deltaf)**2)*np.cos(2*pi*f*(t-x/vphi(f)))
    return ond

def animate(i):
    t=i*dt
    y=onde(x,t)
    line.set_data(x,y)
    return line,

anim=animation.FuncAnimation(fig,animate,frames=800,interval=50,blit=True,repeat=False)

plt.show()