#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 30 21:34:17 2020

@author: joctrash
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

TWOPI = 5*np.pi

fig, ax = plt.subplots(figsize=(8,8))

ka = np.arange(0.0, TWOPI, 0.001)
initial_amp = .5
s = np.sqrt(initial_amp-ka**2)
l, = plt.plot(ka, s, lw=2, label='condition de profondeur du puits')

# DÃ©finition des deux foncitons trigo

f1 = ka*np.tan(ka)
f2 = -ka/np.tan(ka)
f1[np.abs(np.cos(ka)) <= np.abs(np.sin(ka[1]-ka[0]))] = np.nan
f2[np.abs(np.sin(ka)) <= np.abs(np.sin(ka[1]-ka[0]))] = np.nan

plt.plot(ka,f1,label='solutions paires')
plt.plot(ka,f2,label='solutions impaires')

plt.xlabel('kL',fontsize=20)
plt.ylabel('qL',fontsize=20)

ax.xaxis.set_label_coords(1.05, -0.025)

plt.legend(fontsize=15)

ax = plt.axis([0,TWOPI,0,TWOPI])

axamp = plt.axes([0.25, .03, 0.50, 0.02])
# Slider
samp = Slider(axamp, 'Vo', 0, 100, valinit=initial_amp,color='r')

def update(val):
    # amp is the current value of the slider
    amp = samp.val
    # update curve
    l.set_ydata(np.sqrt(amp-ka**2))
    # redraw canvas while idle
    fig.canvas.draw_idle()

# call update function on slider value change
samp.on_changed(update)



plt.show()