学习了一下turtle的中的color、fd、circle的基本用法,画一条彩蛇的蟒蛇还是挺简单的,代码如下
import turtle
def drawSnake(rad, angle, len, neckrad):
# 设置每一段圆弧的颜色
colors = ['black','gray','brown','purple','blue','cyan','green','olive','yellow','orange','pink']
for i in range(len):
turtle.color(colors[i])
# 绘画每一段颜色的两个圆弧
turtle.circle(rad, angle-i*2)
turtle.circle(-rad, angle+i*2)
# 蛇头转弯
turtle.color("red")
# 蛇头头转弯处的过渡
turtle.circle(rad*3/2, angle / 2)
# 画笔直走
turtle.pensize(neckrad*5/2)
turtle.fd(rad/2)
# 画笔转弯
# turtle.circle(neckrad + 1, 180)
# # 画笔转弯后直走
# turtle.fd(rad * 2 / 3)
def init():
# 设置画布大小
turtle.setup(1000, 1000, 0, 0)
# 拿起画笔,无轨迹线
turtle.penup()
# 设置画笔起始点
turtle.goto(0, 200)
# 放下画笔,有轨迹线
turtle.pendown()
# 设置画笔粗细
pythonsize = 20
turtle.pensize(pythonsize)
# 设置起始角度
turtle.seth(-30)
# 设置圆弧的半径、弧度、个数
drawSnake(40, 60, 11, pythonsize / 2)
turtle.exitonclick()
init()