有没有办法在Python3.8中使用rgb颜色?

国际象棋_情人_6

我试图指定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)
国际象棋_情人_6

我发现您需要一个window(或其他变量)=turtle.Screen()然后就可以做window.colormode(255)然后可以改变配色方案

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

有没有办法在带有 Python3 的 Window 上使用 ROS?

有没有办法使用 Python3 (WITHOUT Dataflow) 从 Datastore 命名空间中删除所有实体?

有没有办法在Python3中将列表分组为子列表?

有没有办法将击键发送到Python3中的特定应用程序?

有没有办法在Python中使用PhantomJS?

Python3:有没有办法像python2一样使用telnetlib,而没有ascii编码和b前缀?

有没有办法在python的lambda中执行“ if”

有没有办法在python中禁止舍入?

有没有办法在python中重载+ =?

有没有办法在Python中包含±(正负)?

有没有办法在python中清除屏幕?

有没有办法在python中输入小写?

有没有办法摆脱python列表中的“'”?

有没有办法在python中打印not bool?

有没有办法在相同的conda环境中安装python 3和python 2?

有没有办法使用 SWIG C++ 创建一个 python 模块,它可以在 Python2 和 Python3 中导入

有没有办法在Python字典中附加第3个值?

有没有办法以编程方式清除Python 3中跨平台的终端?

有没有办法在 Python 3 中快速打印和输出结果

有没有办法在python 3中设置int的限制

有没有办法在 python 中使用 sns.barplot 显示不同的颜色?

有没有办法在querySelector中使用*?

有没有办法在watchOS中使用`useProtocolCachePolicy`?

有没有办法在gnuplot中使用通配符?

有没有办法在BottomSheetDialogFragment 中使用AlertDialog?

有没有办法在Firestore中使用GeoFire?

有没有办法在GLSL中使用联合?

有没有办法在JavaScript中使用C ++?

有没有办法在PostgreSQL中使用qualify