|
def get_step():
direction = choice([1,-1])
print(direction)
distence = choice([0,1,2,3,4])
next_xy = direction * distence
return next_xy
def fill_walk(self):
"""计算随机漫步的所有点"""
#不断漫步,直到列表达到指定的长度
while len(self.x_values) < self.num_points:
#决定前进的方向以及沿着这个方向行走的距离
x_step = get_step()
y_step = get_step()
#拒绝原地踏步走
if x_step ==0 and y_step ==0:
continue
#计算下一个点的x和y的值
next_x = self.x_values[-1] + x_step
next_y = self.y_values[-1] + y_step
self.x_values.append(next_x)
self.y_values.append(next_y)
|
|