颜色填充函数
使用Turtle不仅可以画线条,也可以将画出的封闭线条进行填充。开始填充:begin_fill()
设定填充色:fillecolor()
结束填充:end_fill()
实际操作
练习1:画心形importturtle
importrandom
defpink():
color=(1,random.random(),1)
returncolor
defheart(radius,angle:float):
factor=180
#设置朝向
turtle.seth(angle)
#绘制一个radius指定半径的圆
turtle.circle(-radius,factor)
#前进指定距离
turtle.fd(2*radius)
#右转n度
turtle.right(90)
turtle.fd(2*radius)
turtle.circle(-radius,factor)
defrandomrange(min,max):
returnmin+(max-min)*random.random()
defdraw_heart():
#移动到一个绝对坐标
turtle.goto(randomrange(-200,200),randomrange(-200,200))
#在绘制要填充的形状之前调用
turtle.begin_fill()
#设置填充颜色
turtle.fillcolor("red")
heart(randomrange