import turtle
t = turtle.Pen()
turtle.bgcolor("black")
colors = [ "red", "yellow", "blue", "green", "orange",
"purple","white", "brown ", "gray", "pink" ]
family =[] # Set up an empty list for family names
# Ask for the first name
name = turtle.textinput("My family",
"Enter a name,or just hit [ENTER] to end: ")
# Keep asking for names
while name != "":
#Add their name to the family list
family.append(name)
#Ask for another name,or end
name = turtle.textinput("My family",
"Enter a name,or just hit [ENTER] to end: ")
for x in range(100):
t.pencolor(colors[x%len(family)]) # Rotate through the colors
t.penup()#Don't draw the regular spiral lines
t.forward(x*4)
# Just move the turtle on the screen
t.pendown()
# Draw the next family member's name
t.write(family[x%len(family)],font = ("Arial", int((x+4)/4),"bold") )
t.left(360/len(family) +2)#Turn left for our spiral
没什么好大的改动,如下:
import turtle
def Draw_Word(t, familyt, n):
colors = ["red", "yellow", "blue", "green", "orange",
"purple", "white", "brown ", "gray", "pink"]
for x in range(n):
t.pencolor(colors[x % len(familyt)]) # Rotate through the colors
t.penup()#Don't draw the regular spiral lines
t.forward(x*4)
# Just move the turtle on the screen
t.pendown()
# Draw the next family member's name
t.write(familyt[x % len(familyt)], font = ("Arial", int((x + 4) / 4), "bold"))
t.left(360 / len(familyt) + 2) # Turn left for our spiral
t = turtle.Pen()
turtle.bgcolor("black")
family = []
while True:
name = turtle.textinput("My family",
"Enter a name,or just hit [ENTER] to end: ")
if name == "":
break
family.append(name)
if family:
Draw_Word(t, family, 100)
python可以不需要写main函数,你的代码如果没有报错就能直接运行的