博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2017-09-12 21:23  占鹏  阅读(149)  评论(0)    收藏  举报

1.画五角星

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

2.画同心圆

import turtle

for i in range(5):

    turtle.circle((i+1)*10)

    turtle.up()

    turtle.goto(0,-(i+1)*10)

    turtle.down()

3.画个太阳花

from turtle import*

color('red')

fillcolor('blue')

begin_fill()

while True:

    forward(200)

    left(170)

    if(abs(pos()))<1:

        break

end_fill()

done()

4.画五个角星

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

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

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

mygoto(-320,250)
ye(100)
mygoto(-160,300)
ye(25)
mygoto(-110,250)
ye(25)
mygoto(-110,190)
ye(25)
mygoto(-160,140)
ye(25)