- 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
- 对前面的代码进行优化,用for,while,if,def实现:
- 画五角星
import turtle
turtle.speed(6)
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.hideturtle() - 画同心圆
import turtle
for i in range(9):
turtle.up()
turtle.goto(0,-20*(i+1))
turtle.down()
turtle.circle(20*(i+1))
turtle.hideturtle() - 画太阳花
import turtle
turtle.speed(10)
turtle.color('blue','yellow')
turtle.begin_fill()
while True:
turtle.forward(250)
turtle.left(170)
if(abs(turtle.pos()))<1:
break
turtle.end_fill()
done() - 画五个五角星
import turtle
turtle.speed(10)
turtle.color('yellow')
turtle.bgcolor('red')
def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
def drawfive(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()
#大星
mygoto(-300,150)
drawfive(100)
#小星
mygoto(-200,230)
drawfive(50)
mygoto(-150,170)
drawfive(50)
mygoto(-150,100)
drawfive(50)
mygoto(-200,50)
drawfive(50)
turtle.hideturtle() - 画◇花瓣的太阳花
import turtle
turtle.speed(10)
turtle.color("blue")
turtle.fillcolor('yellow')
def drawlx():
for i in range(1,3):
turtle.forward(100)
turtle.right(45)
turtle.forward(100)
turtle.right(135)
for i in range(1,40):
turtle.begin_fill()
drawlx()
turtle.right(20)
turtle.end_fill()
turtle.right(90)
turtle.hideturtle()
- 画五角星