【发布时间】:2020-07-24 13:12:20
【问题描述】:
我试图指定 RGB 颜色以使程序生成随机颜色。我正在尝试如何处理 RGB 颜色,但是它会显示一个错误,即颜色输入错误,更具体地说,“raise TurtleGraphicsError("bad color sequence: %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)
【问题讨论】:
-
请将此减少并增强为预期的MRE。显示中间结果与预期结果的偏差。
-
RGB在哪里?在图片中?我看不到进口 - 不知道你用的是什么笔......
-
很抱歉!我用 turtle 作为 MyPen。
-
stackoverflow.com/q/20320921 建议您检查颜色模式。如果它使用的是 0.0..0.1 模型,那些颜色是无效的。
标签: python python-3.x python-turtle