1
# example based on article in BYTE magazine
2
# 4 bugs starting in separate corners of a square
3
# walk towards each other (this is also the picture on the cover)
7
from tWrapper import tWrapper
9
# wrapper for any additional drawing routines
10
# that need to know about each other
11
class turtleWrapper(tWrapper):
14
def drawMain(dc_local, w, turtleWrapper=turtleWrapper):
15
t = turtleWrapper(dc_local)
18
# create four bugs and send them to the four corners of a square
19
bug1 = turtleWrapper(dc_local)
27
bug2 = turtleWrapper(dc_local)
35
bug3 = turtleWrapper(dc_local)
43
bug4 = turtleWrapper(dc_local)
51
# bug1 is added at the end of the list as a convenience
52
bList = [bug1, bug2, bug3, bug4, bug1]
54
# speed up drawing time
55
tempAutoRefresh = dc_local.autoRefresh
56
dc_local.autoRefresh = 0
58
# the bugs take 400 "steps" toward each other
60
# orient each bug towards its neighbor
61
# by doing this separately from
62
# the step forward, we don't need to maintain
63
# state in a separate list
65
h = bList[b].towards(bList[b + 1])
66
bList[b].setHeading(h)
68
# each bug takes one step forward
73
dc_local.autoRefresh = tempAutoRefresh