import matplotlib.pyplot as plt
import numpy as np
import math as m
from matplotlib.animation import FuncAnimation

xmin = -20
xmax = 100

fig = plt.figure(1)
ax = fig.gca()
ax.set_xlim(xmin,xmax)
ax.set_ylim(-1.5,1.5)

def sinc(x) :
    if x == 0 :
        return 1
    else :
        return m.sin(x)/x

sincnp = np.vectorize(sinc)
k0 = 5

X = np.linspace(xmin,xmax,500)
Y = np.cos(k0*X)

nombrePoints = len(X)

Dk = 0.5
c = 100
vg = 15

l, = ax.plot(X,Y, 'b')

def anime(t) :
    U = Dk*0.5*(X - vg*t)
    V = sincnp(U)
    Y =V*np.cos(k0*X - c*k0*t)
    l.set_ydata(Y)
    return l,

T = 50
dates = np.linspace(-100,T,500)
dateInt = 50


ani=FuncAnimation(fig,anime,frames=dates, blit=False, interval=dateInt, repeat=False)
fig.show()

