标签:yellow pos port bre range from 方式 定义 log
注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
对前面的代码进行优化,用for,while,if,def实现:
画五角星
import turtle
from turtle import *
turtle.color(‘yellow‘,‘yellow‘)
turtle.begin_fill()
for i in range(5):
turtle.forward(200)
turtle.left(-144)
turtle.end_fill()
画同心圆
import turtle
for i in range(5):
turtle.up()
turtle.goto(0,-20*i)
turtle.down()
turtle.circle(20*(i+1))
画太阳花
import turtle
from turtle import *
turtle.speed(100)
turtle.color(‘blue‘,‘yellow‘)
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 yidong(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")
yidong(-300,240)
yidong(-263,163)
wujiaoxing(100)
yidong(-126,211)
wujiaoxing(20)
yidong(-100,160)
wujiaoxing(20)
yidong(-107,116)
wujiaoxing(20)
yidong(-133,95)
wujiaoxing(20)
标签:yellow pos port bre range from 方式 定义 log
原文地址:http://www.cnblogs.com/yishhaoo/p/7508619.html