python英文名译为蟒蛇,下面我们来绘制这条“蟒蛇”
import turtle
def drawSnake(rad,angle,len,neckrad):for i in range(len):turtle.circle(rad,angle)#按圆形爬行turtle.circle(-rad,angle)turtle.circle(rad,angle/2)turtle.fd(rad)#乌龟向前直线爬行turtle.circle(neckrad+1,180)turtle.fd(rad*2/3)def main():turtle.setup(1300,800,0,0) #启动窗口的宽度和高度,左上角在坐标轴的位置pythonsize=30turtle.pensize(pythonsize) #小乌龟运行轨迹的宽度turtle.pencolor("blue") #小乌龟运行轨迹的颜色“#3B9909”turtle.seth(-40) #小乌龟运行的方向drawSnake(40,80,5,pythonsize/2)#启动绘制蟒蛇的功能main()
结果如下: