turtle库(海龟库)
1、画布空间
turtle.setup(width,height,startx,starty)
//(画布的宽,长,画布左上点x,y)
2、空间坐标系:
绝对坐标系中心点为(0,0);
turtle.goto(x,y)——从中心(0,0)到(x,y)
海归坐标体系y左右x前进后退
turtle.circle(r,angle)以海龟的当前位置的左侧某一点为圆心,半径为r,角度为angle的圆曲线行驶
turtle.fd(d)正前方向行驶
turtle.bk(d)后方向行驶
3、角度坐标体系:
绝对角度:绝对坐标系中
turtle.seth(angle)——改变运动方向
海龟角度:海龟坐标体系中
turtle.right(angle)
turtle.left(angle)
4、rgb色彩模式
红绿蓝三个色,每色取值范围0255整数或01小数
白色 255,255,255或1,1,1
黄色 255,255,0或1,1,0
turtle.colormode(mode)mode=1小数值/=255整数值
5、import<库名>
<库名>函数名(<函数参数>)
from<库名>import<函数名>/from<库名>import*
<函数名>(<函数参数>)
import<库名>as<库别名>
<库别名>.<函数名>(<函数参数>)
6、画笔控制函数
turtle.penup()抬起
turtle.pendown()落下
turtle.pensize(width)/turtle.width(width)画笔宽度
turtle.pencolor(color/颜色字符串或r,g,b值) (r,g,b)_小数值 ((r,g,b))_元组值 画笔颜色
7、运动控制函数
走直线
turtle.forward(d)/turtle.fd(d)
走曲线
turtle.cirle(r,extent)
8、方向控制函数
绝对角度
turtle.setheading(angle)/turtle.seth(angle)
海龟角度
turtle.left()/turtle.right()
example❤
import turtle as t
t.setup(700,500,200,200)
t.penup()
t.fd(-250)
t.pendown()
t.pensize(10)
t.pencolor("pink")
t.right(30)
t.fd(200)
t.left(60)
t.fd(200)
t.circle(115,240)
t.circle(1,180)
t.circle(115,240)
t.done