import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
from scipy import special

pi = np.pi
x = np.arange(0,1,0.001)
L = len(x)

def f0(t):
    return [ t , np.zeros(len (t)) ]
def t0_vect(t):
    return [ np.ones(len (t)) , np.zeros(len (t)) ]
def n0_vect(t):
    return [ np.zeros(len (t)) , np.ones(len (t))  ]

graphe_f0 = f0(x)

N1 = 2
N2 = 10
N3 = 50
a1 = 1.6
r1 = 1/(special.jv(0,a1))
a2 = 1.2
r2 = 1/(special.jv(0,a2))
a3 = 0.6
r3 = 1/(special.jv(0,a3))

#definition de Gamma
def gamma1(a):
    return lambda x : np.cos( a*np.cos(2*pi*x)) - special.jv(0,a)
def gamma2(a):
    return lambda x : np.sin( a*np.cos(2*pi*x))
def Gamma_1(a, u):
    return integrate.quad(gamma1(a) , 0, u)[0]
def Gamma_2(a,u):
    return integrate.quad(gamma2(a) , 0, u)[0]
#print( Gamma_1(0.1) )
G1_step1 = np.zeros( L )
G2_step1 = np.zeros( L )
G1_step2 = np.zeros( L )
G2_step2 = np.zeros( L )
G1_step3 = np.zeros( L )
G2_step3 = np.zeros( L )
for i in range( L ):
    G1_step1[i] = Gamma_1(a1, N1*x[i] - np.floor(N1*x[i]) )
    G2_step1[i] = Gamma_2(a1, N1*x[i] - np.floor(N1*x[i]) )
    G1_step2[i] = Gamma_1(a2, N2*x[i] - np.floor(N2*x[i]) )
    G2_step2[i] = Gamma_2(a2, N2*x[i] - np.floor(N2*x[i]) )
    G1_step3[i] = Gamma_1(a3, N3*x[i] - np.floor(N3*x[i]) )
    G2_step3[i] = Gamma_2(a3, N3*x[i] - np.floor(N3*x[i]) )

graphe_f1 = graphe_f0 + r1*(1/N1)*( G1_step1*t0_vect(x) + G2_step1*n0_vect(x) )

def t1_vect(t):
    return r1*( np.cos(a1*np.cos(2*pi*N1*t))*t0_vect(t) + np.sin(a1*np.cos(2*pi*N1*t))*n0_vect(t) )
def n1_vect(t):
    return [ -t1_vect(t)[1] , t1_vect(t)[0] ]

graphe_f2 = graphe_f1 + r2*(1/N2)*( G1_step2*t1_vect(x) + G2_step2*n1_vect(x) )

def t2_vect(t):
    return r2*( np.cos(a2*np.cos(2*pi*N2*t))*t1_vect(t) + np.sin(a2*np.cos(2*pi*N2*t))*n0_vect(t) )
def n2_vect(t):
    return [ -t2_vect(t)[1] , t2_vect(t)[0] ]

graphe_f3 = graphe_f2 + r3*(1/N3)*( G1_step3*t2_vect(x) + G2_step3*n2_vect(x) )

plt.plot( graphe_f0[0], graphe_f0[1] ) # color='navy'
plt.plot( graphe_f1[0], graphe_f1[1] )
plt.plot( graphe_f2[0], graphe_f2[1] )
plt.plot( graphe_f3[0], graphe_f3[1] )
plt.show()



