蟒蛇的基本图形:
turtle绘图体系是Python语言的标准库之一
使用turtle绘图体系首先要设置turtle的绘图窗体,这和java中的GUI界面相似
turtle.setup(width,height,startx.starty)
//startx,stary 可以省略,就是在屏幕中央
turtle空间坐标体系:
绝对坐标:
turtle.goto(100,-100)
turtle.goto(0,0)
海龟坐标:
turtlr.circle(r,angle)//半径和角度
turtle.bk(d)//后退d
turtle.fd(d)//前进d
turtle角度坐标体系:
绝对角度:
turtle.seth(angle)
//seth()改变海龟行进方向
//angle为绝对度数
//seth()只改变方向不行进
海龟角度:
RGB色彩体系:
默认采用小数值,可切换为整数值
turtle.colormode(mode)
turtle画笔控制函数:
turtle.penup()
turtle.pu()
//抬起画笔,海龟在飞行
turtle.pendown()
turtle.pd()
//落下画笔,海龟在爬行
turtle.pensize(width)
turtle.width(width)
//画笔宽度,海龟的腰围
turtle.pencolor(color)
turtle.pencolor("purple")
turtle.pencolor(0.63,0.13,0.94)
turtle.pencolor((0.63,0.13,0.94))
//画笔颜色,海龟在涂装
完整代码:
#PythonDraw.py
import turtle
turtle.setup(650, 350, 200, 200)
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()