- 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
- 对前面的代码进行优化,用for,while,if,def实现:
- 画五角星
import turtle turtle.speed(10) turtle.color('gray') turtle.fillcolor('yellow') turtle.begin_fill() for i in range(5): turtle.forward(200) turtle.right(144) if(abs(turtle.pos()))<1: break turtle.end_fill()
- 画同心圆
import turtle turtle.speed(10) for i in range(1,5): turtle.up() turtle.goto(0,(-20*i)) turtle.down() turtle.circle(20*i)
- 画太阳花
import turtle turtle.speed(10) turtle.color('gray') turtle.fillcolor('pink') turtle.begin_fill() for i in range(38): turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break turtle.end_fill()
- 画五个角星
import turtle turtle.speed(10) turtle.bgcolor('red') def goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def draw(r): turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() goto(-550,200) draw(230) goto(-260,280) turtle.left(45) draw(60) goto(-165,175) turtle.left(50) draw(60) goto(-185,100) turtle.right(95) draw(60) goto(-260,0) turtle.left(45) draw(60) turtle.hideturtle()
- 画◇花瓣的太阳花。
import turtle turtle.speed(10) turtle.color('red') turtle.fillcolor('coral') turtle.begin_fill() for i in range(36): for j in range(2): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) turtle.right(10) turtle.right(90) turtle.forward(400) turtle.end_fill()
- 画五角星