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

画五角星

import turtle
turtle.color('red')
turtle.fillcolor('red')
turtle.begin_fill()
for i in range(5):
    turtle.forward(100)
    turtle.right(144)
turtle.end_fill()
turtle.hideturtle()

结果如图:

 

 

 

画同心圆

import turtle
for i in range(5):
    turtle.up()
    turtle.goto(0,-20*(i+1))
    turtle.down()
    turtle.circle(20*(i+1))
turtle.hideturtle()

结果如图:

 

 

 

画太阳花

import turtle
turtle.color('purple')
turtle.fillcolor('red')
turtle.begin_fill()
while True:
    turtle.forward(200)
    turtle.left(170)
    if(abs(turtle.pos()))<1:
        break
turtle.end_fill()
turtle.hideturtle() 

结果如图:

 

 

画五个五角星

import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')

def sj_goto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()

def sj_draw(r):
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(r)
        turtle.right(144)
    turtle.end_fill()

sj_goto(-350,200)
sj_draw(100)
sj_goto(-180,280)
sj_draw(50)
sj_goto(-125,225)
sj_draw(50)
sj_goto(-125,150)
sj_draw(50)
sj_goto(-175,85)
sj_draw(50)
turtle.hideturtle()

 

结果如图:

 

画◇花瓣的太阳花。

 

import turtle
turtle.color('red')
turtle.fillcolor('purple')
turtle.begin_fill()
for i in range(1,19):
    for i in range(1,3):
        turtle.forward(100)
        turtle.right(45)
        turtle.forward(100)
        turtle.right(135)
    turtle.left(20)
turtle.end_fill()
turtle.right(90)
turtle.forward(400)

结果如图:

 

 


 

posted @ 2017-09-13 16:33  086黄向薇  阅读(146)  评论(0)    收藏  举报