1. 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
  2. 对前面的代码进行优化,用for,while,if,def实现:
    1. 画五角星

      import turtle
      for i in range(5):
          turtle.forward(150)
          turtle.right(144)

      turtle.hideturtle()

       

       

       

    2. 画同心圆
      import turtle
      turtle.bgcolor('green')
      for i in range(5):
          turtle.up()
          turtle.goto(0,-20*(i+1))
          turtle.down()
          turtle.circle(20*(i+1))
      turtle.hideturtle()

       

    3. 画太阳花
      import turtle
      
      turtle.bgcolor('pink')
      turtle.color('green')
      turtle.fillcolor('yellow')
      turtle.begin_fill()
      while True:
          turtle.forward(200)
          turtle.left(160)
          if(abs(turtle.pos()))<1:
              break
      turtle.end_fill()
      turtle.done()

       

    4. 画五个五角星
      import turtle
      turtle.bgcolor('red')
      turtle.color('yellow')
      turtle.fillcolor('yellow')
      
      def l_goto(x,y):
          turtle.up()
          turtle.goto(x,y)
          turtle.down()
      
      def l_draw(r):
          
          turtle.begin_fill()
          for i in range(5):
              turtle.forward(r)
              turtle.right(144)
          turtle.end_fill()
      
      l_goto(-360,190)
      l_draw(150)
      
      
      l_goto(-155,240)
      turtle.left(50)
      l_draw(50)
      
      l_goto(-90,165)
      turtle.left(44)
      l_draw(50)
      
      l_goto(-75,85)
      turtle.left(50)
      l_draw(50)
      
      l_goto(-120,50)
      turtle.left(50)
      l_draw(50)
      
      turtle.hideturtle()
      turtle.done()

       

    5. 画◇花瓣的太阳花。
      import turtle
      
      def draw_center(brad):
          brad.forward(125)
          brad.right(45)
          brad.forward(100)
          brad.right(135)
      
      def draw_flower():
      
          window=turtle.Screen()
          window.bgcolor('pink')
      
          brad=turtle.Turtle()
          brad.shape('turtle')
          brad.color('green')
          brad.speed('fastest')
      
          for i in range(1,18):
              draw_center(brad)
              draw_center(brad)
              brad.left(20)
      
          brad.right(70)
          brad.forward(325)
      
          window.exitonclick()
      
      draw_flower()
      turtle.hideturtle()

       

       

posted on 2017-09-13 16:40  094吴嘉绿  阅读(314)  评论(0)    收藏  举报