条件、循环、函数定义 练习

时间:2023-02-13 22:39:22
  1. 画五角星
  2. import turtle
    for i in range(5):
    turtle.forward(
    200)
    turtle.right(
    144)

    条件、循环、函数定义 练习

     

  3. 画同心圆
  4. import turtle
    for i in range(5):
    turtle.circle(
    20*(1+i))
    turtle.up()
    turtle.goto(0,
    -20*(1+i))
    turtle.down()
    turtle.done()

    条件、循环、函数定义 练习

     

  5. 画太阳花
  6. import turtle
    from turtle import *
    turtle.color('red','yellow')
    turtle.begin_fill()
    while True:
        turtle.speed(10)
        turtle.forward(200)
        turtle.left(170)
        if (abs(pos()))<1:
            break
    turtle.end_fill()
    turtle.done()

    条件、循环、函数定义 练习

     

  7. 画五个五角星
  8. import turtle
    turtle.fillcolor(
    'red')
    turtle.speed(
    10)

    def my_goto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    def my_cd(s):
    turtle.forward(s)
    turtle.left(
    90)
    def my_draw5(r):
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(r)
    turtle.right(
    144)
    turtle.end_fill()



    #国旗红底
    turtle.begin_fill()
    my_goto(
    -270,-180)
    my_cd(
    550)
    my_cd(
    330)
    my_cd(
    550)
    my_cd(
    330)
    turtle.end_fill()
    turtle.fillcolor(
    'yellow')
    turtle.color(
    'yellow')
    my_goto(
    -195,99)
    my_draw5(
    90)

    turtle.left(
    30)
    my_goto(
    -75,130)
    my_draw5(
    30)


    my_goto(
    -45,100)
    my_draw5(
    30)

    turtle.right(
    30)
    my_goto(
    -45,60)
    my_draw5(
    30)

    turtle.right(
    20)
    my_goto(
    -75,21)
    my_draw5(
    30)
    turtle.done()

    条件、循环、函数定义 练习

     

  9. 画◇花瓣的太阳花
  10. import turtle
    turtle.speed(
    10)
    turtle.bgcolor(
    'blue')
    turtle.fillcolor(
    'red')
    def my_draw(s):
    turtle.begin_fill()
    turtle.forward(s)
    turtle.right(
    45)
    turtle.forward(
    100)
    turtle.right(
    135)
    turtle.forward(s)
    turtle.right(
    45)
    turtle.forward(
    100)
    turtle.right(
    135)
    turtle.end_fill()

    for i in range(1,37):
    my_draw(
    100)
    turtle.left(
    10)

    turtle.right(
    90)
    turtle.forward(
    300)
    turtle.done()

    条件、循环、函数定义 练习