我有下面的代码,它应该在一个圆圈周围绘制一圈颜色,但如果在移动到下一个之前打印和更改 8 次,则只有一种颜色
import turtle
def drawCircle(colorList, radius):
for color in colorList:
turtle.color(color)
for i in range(len(colorList)):
turtle.penup()
turtle.setpos(0, -radius)
xpos=turtle.xcor()
ypos=turtle.ycor()
head=turtle.heading()
turtle.begin_fill()
turtle.pendown()
turtle.home()
turtle.setpos(xpos,ypos)
turtle.setheading(head)
turtle.circle(radius)
turtle.end_fill()
turtle.penup()
return
colorList=["#880000","#884400","#888800","#008800",\
"#008888","#000088","#440088","#880088"]
drawCircle(colorList,200)
我怎样才能让圆周围的每条弧都有不同的颜色。这是一个例子 http://www.hgtv.com/decorating-basics/color-wheel-primer/index.html
你会需要这样的东西
def drawSegment(color,x, y, r, angleStart, angleEnd, step=1):
#More efficient to work in radians
radianStart = angleStart*pi / 180
radianEnd = angleEnd*pi / 180
radianStep=step *pi/180
#Draw the segment
turtle.penup()
turtle.setpos(x,y)
turtle.color(color)
turtle.begin_fill()
turtle.pendown()
for theta in arange(radianStart,radianEnd,radianStep):
turtle.setpos(x + r * cos(theta), y + r * sin(theta))
turtle.setpos(x + r * cos(radianEnd), y + r * sin(radianEnd))
turtle.setpos(x, y);
turtle.end_fill()
def drawCircle(colorList,radius):
#do something to draw an equal segment for each color advancing it around 360 degree's
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)