import numpy as np
import math as mt
import random
from matplotlib import pyplot as plt
from matplotlib import animation
x = y = 0
labx = [0]
laby = [0]
n = 100 #int(input("number of moves "))
for i in range(0,n):
x = x + np.cos(float(random.randint(0,360)) * (180 / (mt.pi)))
y = y + np.sin(float(random.randint(0,360)) * (180 / (mt.pi)))
labx.append(x)
laby.append(y)
fig = plt.figure()
line, = plt.plot(labx, laby, "o-", lw = 2)
def init():
line.set_data([], [])
return line,
def animate(n):
line.set_data(labx[:n+1], laby[:n+1])
return line,
anim = animation.FuncAnimation(fig, animate, init_func = init, frames=200, interval=20, blit=True)
plt.show()