在学习了turtle库的基本操作之后做了简单梳理:
import turtle as t
- t.pensize(5) # 设置画笔的大小
- t.colormode(255) # 设置GBK颜色范围为0-255
- t.color((255, 155, 192), “pink”) # 设置画笔颜色和填充颜色(pink)
- t.setup(900, 500) # 设置主窗口的大小为900*500
- t.speed(10) # 设置画笔速度为10
- t.write (“要写的内容”, font = (“字体”, 14 #字号 , “字体风格”))
- t.fd (距离) #向前运行
- t.bk (距离) #向后运行
- -t.circle (圆半径,angle) #向当前heading方向运行,画以r为半径,以angle为圆心角的弧
-t.left (angle) #左转xx度
-t.right(angle) #右转xx度 - t.setheading (angle) #也写t.seth, 改变当前turtle的行进方向,angle为绝对角度
- t.colormode(mode) #1.0: RGB小数模式 ; 255:整数模式
- t.begin_fill () #开始填充标志,与end_fill ()配套使用
-
t.end_fill () #begin_fill 到 end_fill 之间为操作画笔画出的封闭区域
如:
t.color (255,255,0)
t.begin_fill()
t.goto(300,300)
t.goto(100,300)
t.goto(-300,-300)
t.goto(300,-300)
t.end_fill()
画笔控制函数:
t.penup () #抬笔,也可写为 t.pu (),与pendown成对出现
t.pendown () #落笔,也可写为 t.pd (),与penup成对出现
t.pensize (width) #画笔宽度,也写为 t.width
t.pencolor (color) #画笔颜色,color为颜色字符串或rgb值
turtle 角度坐标体系:
绝对坐标:以画布中心位置为(0,0)的平面直角坐标系
相对坐标:以turtle目前所处的位姿为初始态,前后左右四个方向
(想象自己身处二维平面
t.fd (20) # 向turtle当前朝向前进20像素
t.bk (20) # 后退20像素
t.left (90) # 向左转90度
t.right (90) # 向右转90度
turtle 色彩体系(RGB):
t.colormode (255) # 设置RGB值为0-255
t.colormode (1.0) # 设置RGB值为0-1
t.color((255, 155, 192), "pink") # 设置画笔颜色和填充颜色RGB值并命名
t.pencolor() # 设置画笔颜色,也可使用color
t.fillcolor () # 设置填充颜色
turtle 书写功能:
turtle.write 可以用来书写文本,turtle当前位置可以看作是要写字的文本框的左下角
添加参数:turtle.write (“要写的内容”, font = (“字体”,字号,“风格”))
例如:
t.write("今天天气真好", font = ("华文新魏",20 ,"normal")) # 字体为 华文新魏,字号=14,普通样式
t.write("It's a good weather today", font = ("Times New Roman", 16, "bold")) # 字体TNR,字号=16, 加粗
我在练习时使用的时Pycharm集成开发环境,所以中文可以使用,有必要时不要忘记 # -- coding: UTF-8 --