在vscode中写代码,pylint报这个错,但是实际运行却又没有问题
Module 'turtle' has no 'fd' member
主要原因是:turtle并没有向外暴露 fd这个方法,新建一个Turtle对象,然后使用setup方法更为推荐,这样写的话,编辑器也会有代码提示
m = t.Turtle()
m.fd(50)
turtle常用函数
penup() 提起画笔 海龟在空中
pendown() 放下画笔 海龟在地上
pensize(width) 画笔宽度 海龟腰围
pencolor(color) 画笔颜色 海龟身上带的颜料
pencolor("red") 或者 pencolor(0.63, 0.13, 0.94) 或者pencolor((0.63, 0.13, 0.94))
forward(d) 简写fd(d) 海龟向前爬行 d 行进距离,可以为负数
backward(d) 简写bd(d) 海龟向后倒退
circle(r, extend) 海龟 绕着圆心D,根据半径r做圆周运动。圆心D默认是在海龟左侧r距离的位置,extend是绘制角度,默认是360度整圆
setheading(angle) 简写seth(angle) 海龟的朝向角度
left(angle) 海龟向左转
right(angle) 海龟向右转
![](https://img.haomeiwen.com/i12265479/335c3e73738b8614.png)
蟒蛇绘制实例
import turtle
turtle.setup(650, 350, 200, 200)
turtle.Screen
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor("purple")
turtle.seth(-40)
for i in range(4):
turtle.circle(40, 80)
turtle.circle(-40, 80)
turtle.circle(40, 80/2)
turtle.fd(40)
turtle.circle(16, 180)
turtle.fd(40 * 2/3)
turtle.done()
![](https://img.haomeiwen.com/i12265479/be2f4a29739ae4b3.png)
Turtle讲解
-
turtle的绘图窗体
image.png
image.png
-
turtle有两套坐标体系
空间坐标体系 和 角度坐标体系
其中二者都包含下面两种体系,所以细分下来是四种体系。- 绝对坐标 (咱们人类的视角)
- 海龟坐标 (海龟的视角)
空间坐标中的 绝对坐标
turtle.goto(x,y)
image.png
![](https://img.haomeiwen.com/i12265479/0c7e60cd36a36b71.png)
空间坐标中的 海龟坐标
turtle.circle(r, angle)
turtle.fd(d)
turtle.bk(d)
![](https://img.haomeiwen.com/i12265479/bfa2ec55a95b3a36.png)
![](https://img.haomeiwen.com/i12265479/6b9176d3bcfcae96.png)
角度坐标中的 绝对角度
turtle.seth(angle) #set h 设置h
![](https://img.haomeiwen.com/i12265479/2aac5f85ac05d34a.png)
![](https://img.haomeiwen.com/i12265479/e83fd342dd028d60.png)
角度坐标中的 海龟角度
turtle.left(angle)
turtle.right(angle)
![](https://img.haomeiwen.com/i12265479/df988d716e92eddb.png)
![](https://img.haomeiwen.com/i12265479/ed757fc9c74f8924.png)
-
RGB色彩空间
两套表示 0-255 或者 0-1(小数)turtle.colormode(mode)
1.0 : RGB小数模式
255:RGB整数模式image.png
网友评论