使用海龟绘图制作字符旋涡
功能要求
使用海龟绘图制作字符旋涡,在文本框中输入多个“姓名”,最后以空格结束,形成不同名字不同颜色的字符旋涡
实例代码
import turtle
t = turtle.Pen()
t.speed(0)
t.hideturtle()
turtle.bgcolor('pink')
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'white', 'brown']
friend = []
name = turtle.textinput('输入姓名', '请输入姓名或这就按OK按钮结束输入')
while name != '':
friend.append(name)
name = turtle.textinput('输入姓名', '请输入姓名或这就按OK按钮结束输入')
for x in range(100):
t.pencolor(colors[x % len(friend)])
t.penup()
t.forward(x * 4)
t.pendown()
t.write(friend[x % len(friend)], font=('宋体', int((x + 4) / 4), 'bold'))
t.right(360 / len(friend) + 2)
turtle.done()
运行结果
代码分析