#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 13 09:04:33 2026

@author: eddiesaudrais
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.widgets import Slider

# Paramètres
lam = 1.0
L = 6.0
c = 1.0

x = np.linspace(0, L, 400)

def y(x, t, r):
    return (np.cos(2*np.pi*(c*t - x)/lam)
            + r*np.cos(2*np.pi*(c*t - 2*L + x)/lam))

# Figure
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.25)

ax.set_xlim(0, L)
ax.set_ylim(-2, 2)
ax.set_xlabel("x")
ax.set_ylabel("y(x,t)")

# Ligne vide au départ (pas de y=0 affiché)
line, = ax.plot([], [], lw=2)

# Slider pour r
ax_r = plt.axes([0.2, 0.1, 0.6, 0.03])
slider_r = Slider(
    ax=ax_r,
    label='r',
    valmin=-1.0,
    valmax=1.0,
    valinit=0.0,
    valstep=0.01
)

# Animation
t0 = 0.0
dt = 0.05

def update(frame):
    t = t0 + frame * dt
    r = slider_r.val
    line.set_data(x, y(x, t, r))
    return line,

ani = FuncAnimation(
    fig,
    update,
    frames=1000,
    interval=70,
    blit=True
)

plt.show()
