利用turtl进行绘制如下图的同心标靶图,颜色有变比。 color=["pink","purple","red","blue","yellow","orange","coral","brown","yellow","fuchsia"]
时间: 2023-11-05 10:06:08 浏览: 210
利用turtle库可以绘制同心圆,可以自定义一个函数mycircle(x,y,r,cr,cg,cb),其中x,y为绘制圆形的圆心,r为半径,cr,cg,cb为圆形填充的RGB颜色值(0-255),利用这个自定义函数绘制同心圆,如下图所示。根据提供的颜色列表color,可以通过循环来实现颜色的变化。
下面是代码实现:
import turtle
def mycircle(x,y,r,cr,cg,cb):
turtle.goto(x,y)
for i in range(0, 10):
turtle.fillcolor(cr,cg,cb)
turtle.begin_fill()
turtle.circle(r-(i*10))
turtle.penup()
turtle.left(90)
turtle.fd(10)
turtle.right(90)
turtle.pendown()
turtle.end_fill()
cr,cg,cb = cb,cr,cg
turtle.setup(600,600,200,200)
turtle.penup()
turtle.pendown()
turtle.pensize(1)
turtle.colormode(255)
turtle.pencolor(0,0,0)
color=["pink","purple","red","blue","yellow","orange","coral","brown","yellow","fuchsia"]
for i in range(len(color)):
mycircle(0,0,90-i*10,color[i],255-color[i]*2,0)
turtle.done()
--相关问题--:
1. turtle库还有哪些常用的绘图函数?
2. 如何在turtle中绘制正方形和三角形?
3.
阅读全文