import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

import random as rd
from matplotlib.patches import Circle

plt.close('all')


# marche au hasard
def marche(N):
    x = [0]
    y = [0]
    for _ in range(N-1):
        x.append(x[-1] + rd.randint(-1,1))
        y.append(y[-1] + rd.randint(-1,1))
    return x,y


N=100

nbre_marche = 100

fig, ax = plt.subplots()

# (x, z), radius

x,y = marche(10)
x2,y2 = marche(10)

plt.xlim([-50, 50])
plt.ylim([-50, 50])

for i in range(100):
    x.append(x[-1] + rd.randint(-1,1))
    y.append(y[-1] + rd.randint(-1,1))
    x2.append(x[-1] + rd.randint(-1,1))
    y2.append(y[-1] + rd.randint(-1,1))
    ax.set_title('N = {}'.format(N))
    rayon  = (2*len(x))**.5
    cercle = Circle((0, 0), rayon, linewidth=2, edgecolor = 'black', alpha = 0.05)   # (x, z), radius
    ax.add_patch(cercle)

    ax.set_aspect('equal')
    if i == 0:
        line, = ax.plot(x, y,'k')
        line2, = ax.plot(x2, y2,'r')
    else:
        line.set_data(x, y)
        line2.set_data(x2, y2)
    plt.pause(0.1) # pause avec duree en secondes

plt.show()

# fig = plt.figure() # initialise la figure

#
# line, = ax.plot([], [])
#
# plt.xlim(xmin, xmax)
# plt.ylim(-1, 1)
# x,y = marche(10)
# def animate(i):
#     N = 10
#     x.append(x[-1] + rd.randint(-1,1))
#     y.append(y[-1] + rd.randint(-1,1))
#     ax.plot(x,y,'k')
#     rayon  = (2*len(x))**.5
#     cercle = Circle((0, 0), rayon, linewidth=2, edgecolor = 'black', alpha = 0.3)
#     ax.add_patch(cercle)
#     line.set_data(x, y)
#     ax.set_aspect('equal', 'box')
#     ax.set_title('N = {}'.format(len(x)))
#
#     return line,
#
# ani = animation.FuncAnimation(fig, animate, frames=100,
#                               interval=100, blit=True, repeat=False)
# plt.show()