from random import choice
from matplotlib.pyplot import arrow, grid, show, ylim, xlim, plot

def trajet(n):
    L = [ 'droite' , 'gauche' , 'haut' , 'bas' ]
    # liste où l'on mettra les positions du kangourou après chaque saut
    P = [ ]
    (x , y) = (0 , 0) # position initiale du kangourou
    xmin = 0
    xmax = 0
    ymin = 0
    ymax = 0
    for k in range(n):
        direction = choice(L)
        if direction == 'droite':
            x = x + 1
            if x > xmax:
                xmax = x
        elif direction == 'gauche':
            x = x - 1
            if x < xmin:
                xmin = x
        elif direction == 'haut':
            y = y + 1
            if y > ymax:
                ymax = y
        else:
            y = y - 1
            if y < ymin:
                ymin = y

        # on ajoute à la liste P la position du kangourou après le saut
        P.append( (x,y) )

    # on dessine le trajet
    xlim(xmin-1,xmax+1)
    ylim(ymin-1,ymax+1)
    grid()
    old_pos = (0,0)
    plot(0,0,'o')
    for coord in P:
        arrow( old_pos[0] , old_pos[1] , coord[0]-old_pos[0] , coord[1]-old_pos[1] , color='red' , head_width=0.1 , length_includes_head=True)
        old_pos = coord
    plot(old_pos[0],old_pos[1],'o')
    show()
