我正在展示一个用 Python 的 Turtle 模块绘制的孙子图案,他要求看同心圆。我认为使用海龟circle()来绘制它们比编写自己的代码来生成圆要快。哈!我被困住了。我看到生成的圆从乌龟的当前位置开始它的圆周,它的绘制方向取决于乌龟的当前运动方向,但我不知道我需要做什么才能得到同心圆。在这一点上,我对产生同心圆的有效方法不感兴趣:我想看看我必须做什么才能使
这种方式工作:
def turtle_pos(art,posxy,lift):
if lift:
art.penup()
art.setposition(posxy)
art.pendown()
def drawit(tshape,tcolor,pen_color,pen_thick,scolor,radius,mv):
window=turtle.Screen() #Request a screen
window.bgcolor(scolor) #Set its color
#...code that defines the turtle trl
for j in range(1,11):
turtle_pos(trl,[trl.xcor()+mv,trl.ycor()-mv],1)
trl.circle(j*radius)
drawit("turtle","purple","green",4,"black",20,30)
Run Code Online (Sandbox Code Playgroud)