“海龟绘图”程序的第一条语句就是“import turtle”。
turtle知识库:
turtle.setup(width,height,startx,starty)
-setup() 设置窗体的位置和大小
相对于桌面的起始点的坐标以及窗口的宽度高度,若不写窗口的起始点,则默认在桌面的正中心
窗体的坐标原点默认在窗口的中心
turtle.goto(100,100):指从当前的点指向括号内所给坐标
turtle.left(angle)箭头左转
turtle.right(angle)箭头右转
turtle.penup() 别名turtle.pu()画笔抬起,不留下痕迹
turtle.pendown() 别名turtle.pd()画笔落下,留下痕迹
turtle.pensize(width) 别名turtle.width(width) 画笔宽度
turtle.pencolor(color):color为颜色字符串或者rgb值
turtle.forword(d) 别名turtle.fd(d)向前行进 d:行进距离,可以为负数
turtle.circle(r,extent=None)根据半径r,绘制一个extent角度的弧度
r:默认圆心在海龟左侧r距离的位置
import turtle #导入 turtle 模块
turtle.showturtle() #显示箭头
turtle.write("hello") #写字符串
turtle.forward(300) #前进 300 像素
turtle.color("red") #画笔颜色改为 red
turtle.left(90) #箭头左转 90 度
turtle.forward(300)
turtle.goto(0,50) #去坐标(0,50)
turtle.goto(0,0)
turtle.penup() #抬笔。这样,路径就不会画出来
turtle.goto(0,300)
turtle.pendown