标签:方式 优化 break hit forward es2017 定义 war col
1.注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2.对前面的代码进行优化,用for,while,if,def实现:
a.画五角星
import turtle for i in range(5): turtle.forward(100) turtle.right(144) turtle.hideturtle()
b.画同心圆
import turtle turtle.speed(10) for i in range(6): turtle.color(‘purple‘) turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1)) turtle.hideturtle()
c.画太阳花
import turtle turtle.color(‘red‘,‘yellow‘) turtle.speed(10) turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break turtle.end_fill() turtle.hideturtle() done()
d.画五个角星
法1:
import turtle turtle.setup(600,400,0,0) turtle.color(‘yellow‘) turtle.bgcolor(‘red‘) turtle.fillcolor(‘yellow‘) turtle.speed(10) def jzx_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def jzx_draw5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() jzx_goto(-250,75) jzx_draw5(100) jzx_goto(-120,150) jzx_draw5(50) jzx_goto(-80,100) jzx_draw5(50) jzx_goto(-90,30) jzx_draw5(50) jzx_goto(-140,0) jzx_draw5(50) turtle.hideturtle() turtle.done()
法2:
import turtle turtle.setup(600,400,0,0) turtle.color(‘yellow‘) turtle.bgcolor(‘red‘) turtle.fillcolor(‘yellow‘) turtle.speed(10) def jzx_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() jzx_goto(-250,75) turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() turtle.up() turtle.goto(-120,150) turtle.down() turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() jzx_goto(-80,100) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() jzx_goto(-90,30) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() jzx_goto(-140,0) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() turtle.hideturtle() turtle.done()
e.画◇花瓣的太阳花。
import turtle turtle.fillcolor(‘yellow‘) turtle.bgcolor(‘white‘) turtle.speed(10) turtle.begin_fill() for i in range(1,37): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) turtle.left(10) turtle.end_fill() turtle.begin_fill() turtle.right(90) turtle.forward(300) turtle.hideturtle() turtle.end_fill()
标签:方式 优化 break hit forward es2017 定义 war col
原文地址:http://www.cnblogs.com/jzx-089/p/7515511.html