如何采用Python语言绘制一条彩色的蟒蛇
2个回答
2020-02-09
展开全部
你好,可以输入以下程序(个人作了注释,注释不影响最终结果)。:
#画彩色蟒蛇了#import turtle def drawSnake(rad,angle,len,neckrad): mycolor=["black","red","red","blue","yellow"] yocolor=["yellow","green","yellow","red","red"] for i in range(len): turtle.pencolor(mycolor[i]) turtle.circle(rad,angle) #沿着一个圆形爬行# turtle.pencolor(yocolor[i]) turtle.circle(-rad,angle) turtle.pencolor("green") turtle.circle(rad,angle/2) turtle.pencolor("yellow") turtle.fd(rad) turtle.pencolor("red") turtle.circle(neckrad+1,180) turtle.pencolor("green") turtle.fd(rad*2/3)def main(): turtle.setup(1300,800,0,0) #启动图形窗口,宽度,高度,左上角在屏幕中的坐标位置,x,y# pythonsize = 30 turtle.pensize(pythonsize) #运动轨迹的宽度,这里是30像素# turtle.seth(-40) #方向为东南方向40°# drawSnake(40,80,5,pythonsize/2)main()
格式自己整理一下。
#画彩色蟒蛇了#import turtle def drawSnake(rad,angle,len,neckrad): mycolor=["black","red","red","blue","yellow"] yocolor=["yellow","green","yellow","red","red"] for i in range(len): turtle.pencolor(mycolor[i]) turtle.circle(rad,angle) #沿着一个圆形爬行# turtle.pencolor(yocolor[i]) turtle.circle(-rad,angle) turtle.pencolor("green") turtle.circle(rad,angle/2) turtle.pencolor("yellow") turtle.fd(rad) turtle.pencolor("red") turtle.circle(neckrad+1,180) turtle.pencolor("green") turtle.fd(rad*2/3)def main(): turtle.setup(1300,800,0,0) #启动图形窗口,宽度,高度,左上角在屏幕中的坐标位置,x,y# pythonsize = 30 turtle.pensize(pythonsize) #运动轨迹的宽度,这里是30像素# turtle.seth(-40) #方向为东南方向40°# drawSnake(40,80,5,pythonsize/2)main()
格式自己整理一下。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询