~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/turtle/scripts/4bugs.txt

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2006-11-12 17:52:13 UTC
  • mfrom: (2.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061112175213-tv8bnl6rtpa2qw1o
Tags: 0.8.1-8.1
* Non-maintainer upload.
* Fix path to findfiles, codeEditor and resourceEditor:
   + patch from Ernest ter Kuile <ernestjw@xs4all.nl>. (Closes: #397018)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
4
 
# November 1982
5
 
# p. 236 - 240
6
 
 
7
 
from tWrapper import tWrapper
8
 
 
9
 
# wrapper for any additional drawing routines
10
 
# that need to know about each other
11
 
class turtleWrapper(tWrapper):
12
 
    pass
13
 
 
14
 
def drawMain(dc_local, w, turtleWrapper=turtleWrapper):
15
 
    t = turtleWrapper(dc_local)
16
 
    t.cls()
17
 
 
18
 
    # create four bugs and send them to the four corners of a square
19
 
    bug1 = turtleWrapper(dc_local)
20
 
    bug1.color('magenta')
21
 
    bug1.st()
22
 
    bug1.pu()
23
 
    bug1.rt(45)
24
 
    bug1.fd(300)
25
 
    bug1.pd()
26
 
 
27
 
    bug2 = turtleWrapper(dc_local)
28
 
    bug2.color('green')
29
 
    bug2.st()
30
 
    bug2.pu()
31
 
    bug2.rt(135)
32
 
    bug2.fd(300)
33
 
    bug2.pd()
34
 
 
35
 
    bug3 = turtleWrapper(dc_local)
36
 
    bug3.color('blue')
37
 
    bug3.st()
38
 
    bug3.pu()
39
 
    bug3.rt(225)
40
 
    bug3.fd(300)
41
 
    bug3.pd()
42
 
 
43
 
    bug4 = turtleWrapper(dc_local)
44
 
    bug4.color('orange')
45
 
    bug4.st()
46
 
    bug4.pu()
47
 
    bug4.rt(315)
48
 
    bug4.fd(300)
49
 
    bug4.pd()
50
 
 
51
 
    # bug1 is added at the end of the list as a convenience
52
 
    bList = [bug1, bug2, bug3, bug4, bug1]
53
 
 
54
 
    # speed up drawing time
55
 
    tempAutoRefresh = dc_local.autoRefresh
56
 
    dc_local.autoRefresh = 0
57
 
 
58
 
    # the bugs take 400 "steps" toward each other
59
 
    for i in range(430):
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
64
 
        for b in range(4):
65
 
            h = bList[b].towards(bList[b + 1])
66
 
            bList[b].setHeading(h)
67
 
    
68
 
        # each bug takes one step forward
69
 
        for b in range(4):
70
 
            bList[b].fd(1)
71
 
        dc_local.refresh()
72
 
 
73
 
    dc_local.autoRefresh = tempAutoRefresh
74
 
 
75
 
    for b in range(4):
76
 
        bList[b].ht()
77