如何让乌龟将这个方块向右移动36次?

时间:2019-07-17 15:22:51

标签: python python-2.7 turtle-graphics

我正在尝试将正方形向右移动并绘制36个正方形以在其中画一个圆:

def draw_art(x,y):
    print("Started the op")

    window = turtle.Screen()
    window.bgcolor("blue")
    print("start the drwaing")
    c =0
    brad = turtle.Turtle()
    brad.shape("turtle")
    brad.color("green")
    brad.speed(3)
    print("enter loop")
    for i in range(1,37):
        draw_square(x,y)
        brad.right(10)
        window.exitonclick()


draw_art(200,90)

1 个答案:

答案 0 :(得分:0)

这可能使您更接近要执行的操作。它定义了缺少的draw_square()函数,然后在一个圆中绘制了36个正方形:

from turtle import Screen, Turtle

def draw_square(turtle):
    for _ in range(4):
        turtle.forward(50)
        turtle.right(90)

def draw_art(turtle, x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()

    for _ in range(36):
        draw_square(turtle)
        turtle.right(10)

print("Started the app")
window = Screen()
window.bgcolor('blue')

brad = Turtle()
brad.shape('turtle')
brad.color('green')
brad.speed('fastest')  # because I have no patience

print("Start the drawing")
draw_art(brad, 200, 90)

brad.hideturtle()

window.exitonclick()

enter image description here