python turtle教程5

2025-10-21 05:26:39

1、这里我主要介绍一些颜色控制,包括画笔颜色和填充颜色。

画笔颜色控制 pencolor

turtle.pencolor()#没有参数则返回当前画笔的颜色

turtle.pencolor('#33cc8c')#输入颜色对应十六进制

turtle.pencolor(0.5,0.5,0.5)#三个元素对应着r,g,b大小默认需要在0-1之间

turtle.pencolor((0,1,0))#tuple的形式也行

可以使用colormode(255)将0-1映射为0-255型

python turtle教程5

python turtle教程5

python turtle教程5

python turtle教程5

2、填充颜色改变 fillcolor 和 pencolor 的用法基本一致

turtle.fillcolor()#没有参数则返回当前填充的颜色

turtle.fillcolor('#33cc8c')#输入颜色对应十六进制

turtle.fillcolor(0.5,0.5,0.5)#三个元素对应着r,g,b大小默认需要在0-1之间

turtle.fillcolor((0,1,0))#tuple的形式也行

python turtle教程5

python turtle教程5

python turtle教程5

python turtle教程5

3、直接合并pencolor和fillcolor使用color函数

turtle.color()#没有参数则返回当前画笔的颜色和填充的颜色

用法与pencolor和fillcolor一致,只是要输入两个参数。

python turtle教程5

python turtle教程5

4、填充形状 begin_fill 告知开始 end_fill 告知结束 

turtle.begin_fill()将当前位置作为起点,并告知程序开始启动填充图形。

turtle.end_fill()将当前位置作为重点,并告知程序关闭填充图形。

当开始和结束没有形成闭合区域会默认开始和结束点连接在一起

python turtle教程5

python turtle教程5

5、判断当前是否正在填充 filling

turtle.filling()

不在填充为false

正在填充为True

python turtle教程5

6、重新开始作画  reset 和 clear

turtle.clear() 只消除作画痕迹,画布的属性还在

turtle.reset() 全部重来,参数也变为默认

python turtle教程5

python turtle教程5

7、写文本text write()

turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))

arg 为要写的字符串 move 为False 则箭头不移动 为True 则移动

python turtle教程5

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢