我试图指定 RGB 颜色以使程序生成随机颜色。我正在尝试如何处理 RGB 颜色,但它会显示错误颜色输入,更具体地说,“raise TurtleGraphicsError("bad color sequence: %s" % str(color)) turtle.TurtleGraphicsError: bad color sequence : (0, 255, 0)"
from random import randint
myPen = turtle.Turtle()
myPen.ht()
myPen.speed(0)
myPen.pencolor(0,255,0)
myPen.begin_fill()
points = [[-500,-400],[0,500],[500,-400]] #size of triangle
def getMid(p1,p2):
return ( (p1[0]+p2[0]) / 2, (p1[1] + p2[1]) / 2) #find midpoint
def triangle(points,depth):
myPen.up()
myPen.goto(points[0][0],points[0][1])
myPen.down()
myPen.goto(points[1][0],points[1][1])
myPen.goto(points[2][0],points[2][1])
myPen.goto(points[0][0],points[0][1])
if depth>0:
z=(randint(0,255),randint(0,255),randint(0,255))
myPen.fillcolor(z)
triangle([points[0],
getMid(points[0], points[1]),
getMid(points[0], points[2])],
depth-1)
triangle([points[1],
getMid(points[0], points[1]),
getMid(points[1], points[2])],
depth-1)
triangle([points[2],
getMid(points[2], points[1]),
getMid(points[0], points[2])],
depth-1)
triangle(points,7)