python code:
1
2
3
4
5
6
7
8.
Ctrl-Enter to run 惊喜不断(clear output) .
import turtle
import random
def main():
tList = []
head = 0
numTurtles = 10
for i in range(numTurtles):
nt = turtle.Turtle() # Make a new turtle, initialize values
nt.setheading(head)
nt.pensize(2)
nt.color(random.randrange(256),random.randrange(256),random.randrange(256))
nt.speed(10)
nt.tracer(30,0)
tList.append(nt) # Add the new turtle to the list
head = head + 360/numTurtles
for i in range(100):
moveTurtles(tList,15,i)
w = tList[0]
w.up()
w.goto(-130,40)
w.write("Happy Birthday !",True,"center","30px Arial")
w.goto(-130,-35)
w.write("Yao",True,"center","30px Arial")
def moveTurtles(turtleList,dist,angle):
for turtle in turtleList: # Make every turtle on the list do the same actions.
turtle.forward(dist)
turtle.right(angle)
main()
Output:
命令行模式: