Turtle Herd

Back to index

The turtles are actually hidden in this example program, but if you want to see them in action add an e.shape("turtle") line and get rid of the e.ht() line. Otherwise, just get this example up and running.
#!/usr/bin/python import turtle s=turtle.Pen() s.pencolor("yellow") t=turtle.Pen() t.pencolor("orange") p=turtle.Pen() p.pencolor("cyan") t.screen.bgcolor("black") herd = [s,t,p] stp = [-100,0,100] ct = 0 for e in herd: e.pensize=2 e.speed(9) e.ht() e.penup() e.setpos(stp[ct],0) e.seth(72) e.pendown() ct+=1 for i in range(0,5): for e in herd: e.fd(40) e.rt(144) turtle.mainloop()
The for e in herd: line is the most interesting line in this program. It allows you to use e as a proxy for the three instances of turtle.Pen() which are used in this demo program.

Notice that the three turtles don't actually move simultaneously. They just take turns in rapid succession, which might make it look like their moving at the same time, but they're not. In fact, getting true synchronization using the turtle library as it is written may not be possible, but that's an advanced issue that is of only theoretical interest at this moment.


ASSIGNMENT: Your assignment is fairly easy. All you have to do is get nine stars to be drawn at the same time. Arrange them in a 3x3 grid and make each star a different color.