【发布时间】:2019-03-23 03:42:44
【问题描述】:
我正在尝试更改屏幕上显示的圆圈的颜色和#。到目前为止,我已经想出了如何以递归模式使所有这些颜色都变成不同的颜色,但我需要帮助找出如何添加更多颜色。附件是我所拥有的与我需要实现的。
我的代码
import turtle
import colorsys
def draw_circle(x,y,r,color):
turtle.seth(0)
turtle.up()
turtle.goto(x,y-r)
turtle.down()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
def draw_recursive_circles(x,y,r,color,n):
if n == 0:
return
draw_circle(x,y,r,color)
colors = ['red','orange','yellow','green','blue','purple']
i = 0
for angle in range(30,360,60):
turtle.up()
turtle.goto(x,y)
turtle.seth(angle)
turtle.fd(r*2)
draw_recursive_circles(turtle.xcor(),turtle.ycor(),r/3,colors[i],n-1)
i += 1
turtle.tracer(0)
turtle.hideturtle()
turtle.speed(0)
draw_recursive_circles(0,0,100,'red',5)
turtle.update()
【问题讨论】:
标签: python recursion turtle-graphics