Python Turtle:使用 circle() 方法绘制同心圆

the*_*lma 5 python turtle-graphics

我正在展示一个用 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)

Noe*_*lkd 5

你可以这样做:

import turtle

turtle.penup()
for i in range(1, 500, 50):
    turtle.right(90)    # Face South
    turtle.forward(i)   # Move one radius
    turtle.right(270)   # Back to start heading
    turtle.pendown()    # Put the pen back down
    turtle.circle(i)    # Draw a circle
    turtle.penup()      # Pen up while we go home
    turtle.home()       # Head back to the start pos
Run Code Online (Sandbox Code Playgroud)

这创建了下面的图片:

在此处输入图片说明

基本上它将海龟向下移动一个半径长度以将所有圆的中心点保持在同一位置。