# _*_ coding: utf-8 _*_
__author__ = 'pythonwu'
__date__ = "2018/6/15 16:09"
from random import choice,randint
import matplotlib.pyplot as plt
class PersonMovement():
def __init__(self,walk_nums = 10):
self.walk_nums = walk_nums #移动的次数
self.x_values = [0] #x方向轨迹坐标
self.y_values = [0] #y方向的轨迹坐标
def move(self):
while len(self.x_values) < self.walk_nums:
x_direction = choice([-1,1]) # x轴运动方向
x_distance = randint(0,20) #x轴运动距离
x_step = x_direction *x_distance
y_direction = choice([-1,1]) #y轴运动方向
y_distance = randint(0,20) #y轴运动距离
y_step = y_direction *y_distance
if x_step !=0 or y_step !=0:
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)
<