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

xmin = -50
xmax = 50

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

def gaussienne(x) :
    return np.exp(-x*x)

### Construction de la partie OPPS de l'onde

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

nombrePoints = len(X)

Dk = 0.5   # permet d'ajuster la largeur de la gaussienne dans l'espace des k
vphi = 20  # Vitesse de phase
vg = 0     # Vitesse de groupe

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

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

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


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

