练习
a、画五角星。
import turtle
for i in range(5):
turtle.forward(200)
turtle.right(144)
b、画同心圆。
import turtle for i in range(5): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1)) turtle.done()
c、画太阳花。
from turtle import * color('yellow','green') begin_fill() while True: forward(200) left(170) if(abs(pos()))<1: break end_fill()
d、画五个五角星
import turtle
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(-300,175)
my_draw5(100)
my_goto(-150,300)
my_draw5(50)
my_goto(-100,200)
my_draw5(50)
my_goto(-100,100)
my_draw5(50)
my_goto(-150,0)
my_draw5(50)
e、画◇花瓣的太阳花。
import turtle turtle.speed(10) turtle.fillcolor("yellow") turtle.pencolor("red") turtle.begin_fill() def my_draw(): for i in range(1,3): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) for i in range(1,40): my_draw() turtle.right(10) turtle.end_fill() turtle.right(30) turtle.forward(50) turtle.hideturtle()