zoukankan      html  css  js  c++  java
  • 四、条件、循环、函数定义 练习

    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()

  • 相关阅读:
    [Gym
    [Codeforces995C]Leaving the Bar 瞎搞
    [hdu3685]Rotational Painting 凸包 重心
    [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
    [hdu4667]Building Fence 计算几何 瞎瘠薄搞
    [hdu3934] 凸包 旋转卡壳
    [Codeforces50C]Happy Farm 5 凸包
    [Codeforces166B]Polygons 凸包
    mex(线段树+离散化)
    CF798D 糖果(思维题)
  • 原文地址:https://www.cnblogs.com/Green-/p/7515745.html
Copyright © 2011-2022 走看看