【问题标题】:How do I get turtle to move this square right 36 times?如何让乌龟向右移动这个正方形 36 次?
【发布时间】:2019-07-17 15:22:51
【问题描述】:

我正在尝试将正方形向右移动并绘制 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)

【问题讨论】:

    标签: python python-2.7 turtle-graphics


    【解决方案1】:

    这可能会让你更接近你想要做的事情。它定义了缺少的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()
    

    【讨论】:

      猜你喜欢
      • 2022-10-15
      • 2021-07-26
      • 2014-05-22
      • 2014-12-01
      • 2019-07-25
      • 2015-09-05
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      相关资源
      最近更新 更多