1、注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2、对前面的代码进行优化,用for,while,if,def实现:
画五角星
import turtle
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor("yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
画同心圆
import turtle
turtle.speed(100)
for i in range(10):
turtle.up()
turtle.goto(0,-20*i)
turtle.down()
turtle.circle(20*(i+1))
turtle.write(10-i)
画太阳花
import turtle
turtle.speed(100)
turtle.color("pink")
turtle.fillcolor("blue")
turtle.begin_fill()
while True:
turtle.forward(200)
turtle.left(170)
if (abs(turtle.pos()))<1:
break
turtle.end_fill()
画五个角星
import turtle
turtle.speed(10)
def weizhi(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
def wujiaoxing(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.left(-144)
turtle.end_fill()
turtle.bgcolor("red")
turtle.color("yellow","yellow")
weizhi(-300,240)
weizhi(-263,163)
wujiaoxing(100)
weizhi(-125,211)
wujiaoxing(20)
weizhi(-105,160)
wujiaoxing(20)
weizhi(-110,115)
wujiaoxing(20)
weizhi(-135,85)
wujiaoxing(20)