700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > pythonturtle填充颜色函数_python turtle库颜色填充-绘制心形

pythonturtle填充颜色函数_python turtle库颜色填充-绘制心形

时间:2019-12-15 15:39:24

相关推荐

pythonturtle填充颜色函数_python turtle库颜色填充-绘制心形

颜色填充函数

使用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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。