标签:draw 优化 raw ima begin 定义 标准 两种 code
1.注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2.对前面的代码进行优化,用for,while,if,def实现:
1.画五角星
import turtle turtle.bgcolor(‘red‘) turtle.color(‘yellow‘) 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.画同心圆
from turtle import* bgcolor(‘pink‘) shape(‘turtle‘) color(‘blue‘) for i in range(5): up() goto(0,-10*(i+1)) down() circle(10*(i+1)) hideturtle()
done()
3.画太阳花
from turtle import* speed(100) shape(‘turtle‘) color(‘red‘, ‘yellow‘) begin_fill() while True: forward(300) left(230) if abs(pos())<1: break end_fill() hideturtle() done
4.画五个五角星
import turtle turtle.speed(100) turtle.bgcolor(‘red‘) turtle.color(‘yellow‘) 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,200) my_draw5(100) my_goto(-150,280) turtle.left(50) my_draw5(30) my_goto(-100,220) turtle.left(50) my_draw5(30) my_goto(-85,155) turtle.left(50) my_draw5(30) my_goto(-120,110) turtle.left(50) my_draw5(30) turtle.hideturtle() turtle.done()
5.画◇花瓣的太阳花。
import turtle turtle.speed(100) turtle.fillcolor("blue") turtle.pencolor("yellow") turtle.begin_fill() def draw_l(): 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_l() turtle.right(10) turtle.end_fill() turtle.right(90) turtle.forward(300) turtle.hideturtle()
标签:draw 优化 raw ima begin 定义 标准 两种 code
原文地址:http://www.cnblogs.com/33333-/p/7516654.html