画一条可爱的python(蟒蛇):
import turtle#引入库函数turtle(画图的小乌龟)
def drawSnake(rad, angle, len, neckrad):
for i in range(len):
turtle.circle(rad, angle)#画一段圆弧,半径rad(为正在起始点右边,为负在起始点左边),对应圆心角angle
turtle.circle(-rad, angle)
turtle.circle(rad, angle/2)
turtle.fd(rad)#画直线,长度:rad
turtle.circle(neckrad+1,180)
turtle.fd(rad*2/3)
def main():
turtle.setup(1300,1300,0,0)#初始化画图界面的大小1300*1300,左上角坐标(0,0)
pythonsize = 30
turtle.pensize(pythonsize)#画笔大小30
turtle.pencolor(‘purple’)#画笔颜色
turtle.seth(-40)#乌龟画笔起始方向
drawSnake(40,80,3,pythonsize/2)#调用函数开始画图
main()
运行之后就能看到可爱蟒蛇的绘画过程了!