turtle画图报错
import turtleimport 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:} 求求了 这个代码是想画N个颜色随机的同心圆 本帖最后由 南归 于 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)
# 但内层圆会被覆盖,需要继续修改代码 南归 发表于 2021-6-7 18:26
那应该如何让同心圆颜色各不相同啊集美 Dr.阿巴阿巴 发表于 2021-6-8 18:59
那应该如何让同心圆颜色各不相同啊集美
没研究过turtle,不会画同心圆
页:
[1]