我试图指定RGB颜色以使程序生成随机颜色。我正在尝试如何做RGB颜色,但是会显示一个错误,指出它输入的颜色不好,更具体地说,是“ raise TurtleGraphicsError(“坏的颜色序列:%s”%str(color))turtle.TurtleGraphicsError:坏的颜色序列:(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)
我发现您需要一个window
(或其他变量)=turtle.Screen()
。然后就可以做window.colormode(255)
然后可以改变配色方案
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句