main code
import matplotlib.pyplot as plt
from refract import random_move
while True:
rw = random_move(5000)
rw.track()
pointsv = list(range(rw.points))
fed = input("you need scatter/ plot: y/n ")
if fed == 'y':
plt.scatter(rw.xv,rw.yv, c= pointsv ,cmap=plt.cm.Greens, s = 2)
plt.show()
if fed == 'n':
plt.plot(rw.xv,rw.yv, c = [0,0.5,0.5], linewidth = 2)
plt.show()
class definition
class .....................
from random import choice
class random_move():
def __init__(self,points):
self.xv = [0]
self.yv = [0]
self.points= points
def track(self):
xv= getstep()
yv= getstep()
def getstep(self):
dxv = [0]
while len(dxv) < self.points:
xd = choice([1])
xva = choice([3,4,5,7,8,9])
xt= xd*xva
if xt == 0:
continue
nx = dxv[-1]+xt
dxv.append(nx)
return dxv
final output:
error:
---------------------------------------------------------------------------
NameError: name 'getstep' is not defined