条件、循环、函数定义 练习
1、画五角星
import turtle >>> turtle.pencolor("red") >>> turtle.pensize(1) >>> turtle.fillcolor("yellow") >>> turtle.begin_fill() >>> for i in range(5): turtle.forward(100) turtle.right(144) >>> turtle.end_fill() >>> turtle.hideturtle() >>> turtle.done()
2、画同心圆
import turtle for i in range(3): turtle.circle(10*(i+1)) turtle.up() turtle.goto(0,-10*(i+1)) turtle.down() turtle.hideturtle() turtle.done()
3、画太阳花
from turtle import* color("red","yellow") begin_fill() while True: forward(200) left(170) if(abs(pos()))<1: break end_fill() done()
4、画五个五角星
import turtle turtle.setup(800,600,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(-350,180) my_draw5(150) my_goto(-175,250) turtle.left(50) my_draw5(50) my_goto(-100,173) turtle.left(44) my_draw5(50) my_goto(-70,80) turtle.left(50) my_draw5(50) my_goto(-130,50) turtle.left(50) my_draw5(50) turtle.hideturtle() turtle.done()
5、画◇花瓣的太阳花
import turtle turtle.speed("fastest") turtle.fillcolor("yellow") turtle.pencolor("red") turtle.begin_fill() def draw_art(): for i in range(1,3): turtle.forward(150) turtle.right(45) turtle.forward(150) turtle.right(135) for i in range(1,37): draw_art() turtle.left(10) turtle.end_fill() turtle.forward(400) turtle.hideturtle() turtle.done()