样例Python蛇
#PythonDraw.py #调用turtle库 import turtle #设置窗口大小(窗口长度、窗口宽度、窗口距离屏幕的距离) turtle.setup(650,350,200,200) #penup抬起画笔 turtle.penup() #fd向后画250个像素的直线 turtle.fd(-250) #pendown放下画笔 turtle.pendown() #pensize画笔尺寸为25个像素 turtle.pensize(25) #pencolor画笔颜色函数 turtle.pencolor("purple") #seth函数全程为setheading(angle):控制海龟角度 turtle.seth(-40) #for...in...:循环语句 #range()函数,产生循环计数序列 #range(N):产生0到N-1的整数序列,共N个 #range(M,N):产生M到N-1的整数序列,共N-M个 for i in range(4): turtle.circle(40,80) turtle.circle(-40,80) #circle()函数,运动控制函数,第一个参数为半径,第二个参数为角度 turtle.circle(40,40) turtle.fd(40) turtle.circle(16,180) turtle.fd(48*2/3) turtle.done()
正方形
#正方形1 import turtle turtle.pensize(5) turtle.fd(50) turtle.seth(90) turtle.fd(50) turtle.seth(180) turtle.fd(50) turtle.seth(270) turtle.fd(50) ''' ''' #正方形2 import turtle turtle.pensize(5) for i in range(4): turtle.fd(50) turtle.left(90) '''
六边形
#六边形 import turtle turtle.pensize(5) for i in range(6): turtle.fd(50) turtle.left(60) '''
内角100度的叠边形
import turtle turtle.pensize(5) for i in range(9): turtle.fd(100) turtle.left(80)
风轮绘制
#风轮绘制 import turtle turtle.pensize(5) for i in range(4): turtle.fd(150) turtle.right(90) turtle.circle(-150,45) turtle.goto(0,0) turtle.left(45)