颜色填充函数
使用Turtle不仅可以画线条,也可以将画出的封闭线条进行填充。开始填充:begin_fill()
设定填充色:fillecolor()
结束填充:end_fill()
实际操作
练习1:画心形import turtle
import random
def pink():
color = (1, random.random(), 1)
return color
def heart(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)
def randomrange(min, max):
return min + (max- min)*random.random()
def draw_heart():
# 移动到一个绝对坐标
turtle.goto(randomrange(-200, 200), randomrange(-200, 200))
# 在绘制要填充的形状之前调用
turtle.begin_fill()
# 设置填充颜色
turtle.fillcolor("red&