我试图在python中为rhino创建一个步进函数, 该函数应该在随机方向上迈出一步,而不是向后退。 我如何防止退后?
import rhinoscriptsyntax as rs
import random as r
r.seed(seed)
class Walker:
def __init__(self):
self.x = 0
self.y = 0
def point(self):
shape = rs.AddPoint(self.x, self.y, 0)
return shape
def step(self):
choice = r.randint(0,3)
choice = r.randint(1,3)
if (choice == 0):
self.x = self.x + r.choice(uList)
elif (choice == 1):
self.x = self.x - r.choice(uList)
elif (choice == 2):
self.y = self.y + r.choice(uList)
else:
self.y = self.y - r.choice(uList)
uList = [8,11,14]
w = Walker()
pList = []
for t in range(time):
w.step()
pList.append(w.point())
for t-1 in range(time):
a = pList
答案 0 :(得分:0)
这一行:
choice = r.randint(0,3)
随机选择4个方向中的一个。但如果你不想倒退,那么你只需要向前,向左和向右。因此,请将参数更改为randint()
,以便它只从3个可能的数字中选择,避免与您正在调用向后的方向对应的数字,无论哪个。