Dr.阿巴阿巴 发表于 2021-6-7 17:53:24

turtle画图报错

import turtle
import random
turtle.pencolor("green")
turtle.pensize(10)
turtle.pendown()
turtle.setup(800,600,30,30)
n = int(input())
for i in range(n):
    a = random.randrange(0,256)
    b = random.randrange(0,256)
    c = random.randrange(0,256)
    turtle.fillcolor(a,b,c)
    turtle.begin_fill()
    turtle.penup()
    turtle.goto(0,-50*(i+1))
    turtle.pendown()
    turtle.circle(50*(i+1))
    turtle.end_fill()
turtle.done()
hxdm这个报错显示
Traceback (most recent call last):
File "C:\Users\haishan\Desktop\test.py", line 12, in <module>
    turtle.fillcolor(a,b,c)
File "<string>", line 8, in fillcolor
File "C:\Users\haishan\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 2289, in fillcolor
    color = self._colorstr(args)
File "C:\Users\haishan\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 2697, in _colorstr
    return self.screen._colorstr(args)
File "C:\Users\haishan\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 1167, in _colorstr
    raise TurtleGraphicsError("bad color sequence: %s" % str(color))
turtle.TurtleGraphicsError: bad color sequence: (57, 88, 128)
{:10_307:} 求求了

Dr.阿巴阿巴 发表于 2021-6-7 17:54:17

这个代码是想画N个颜色随机的同心圆

南归 发表于 2021-6-7 18:26:11

本帖最后由 南归 于 2021-6-7 18:27 编辑

# 看了一下源码发现了这个,既然乘x的话,那就控制在0-1之内,乘完后r,g,b也在0-255之间,
修改为以下
a = random.random()
b = random.random()
c = random.random()
turtle.fillcolor(a, b, c)

# 但内层圆会被覆盖,需要继续修改代码

Dr.阿巴阿巴 发表于 2021-6-8 18:59:15

南归 发表于 2021-6-7 18:26


那应该如何让同心圆颜色各不相同啊集美

南归 发表于 2021-6-8 22:33:37

Dr.阿巴阿巴 发表于 2021-6-8 18:59
那应该如何让同心圆颜色各不相同啊集美

没研究过turtle,不会画同心圆
页: [1]
查看完整版本: turtle画图报错