我需要重新创建这张照片,颜色和全部。我在定位乌龟以堆叠圆圈时遇到麻烦。
我已经尝试过setheading()
和setposition()
。
我尝试过的代码:
turtle.circle(50)
turtle.setheading(270)
答案 0 :(得分:0)
您具有绘制圆形所需的两个命令。您需要的其他命令是fillcolor()
,begin_fill()
及其配套文件end_fill()
:
import turtle
turtle.setheading(0)
turtle.fillcolor('blue')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.setheading(90)
turtle.fillcolor('green')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.setheading(180)
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.setheading(270)
turtle.fillcolor('cyan')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.done()
我们可以使用Python循环做得更好:
import turtle
for quadrant, color in enumerate(['blue', 'green', 'yellow', 'cyan']):
turtle.setheading(90 * quadrant)
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.done()
如果您想挑战自己,请运用所学的知识解决上述问题,并阅读extent
的{{1}}参数,以得出此变化形式:
您可能还需要使用turtle.circle()
和/或left()
进行绘制,并了解半径的符号如何影响right()
。