YWEIEN

导航

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

1,画太阳花
from turtle import *
color('red','blue')
begin_fill()
while True:
	forward(200)
	left(165)
	if (abs(pos()))<1:
		break
end_fill()
done()

2,画五角星

 

from turtle import *
color('red','black')
begin_fill()
while True:
	forward(200)
	left(144)
	if (abs(pos()))<1:
		break
end_fill()
done()
	

  

3,画同心圆

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

  

 

4,画五个五角星

import turtle
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor('red')
turtle.fillcolor("yellow")
def my_goto(x,y):
	turtle.up()
	turtle.goto(x,y)
	turtle.down()

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

	
my_goto(-250,75)
my_draw5(100)

my_goto(-100,150)
my_draw5(50)

my_goto(-75,75)
my_draw5(50)

my_goto(-85,10)
my_draw5(50)

my_goto(-110,-40)
my_draw5(50)

  

 

5,画◇花瓣的太阳花

from turtle import *

color('red','black')
begin_fill()
speed(10)

for i in range(20):
    while True:
        forward(50)
        left(50)
        forward(50)
        left(130)
        forward(50)
        left(50)
        forward(50)
        if(abs(pos()))<1:
            break
end_fill()
done()

  

 

posted on 2017-09-13 16:09  YWEIEN  阅读(160)  评论(0编辑  收藏  举报