-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwander_stalk.py
More file actions
63 lines (45 loc) · 1.4 KB
/
wander_stalk.py
File metadata and controls
63 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from swampy.TurtleWorld import *
import random
class Disco(Turtle):
"""a Disco is a kind of Turtle that dances and changes colors"""
def __init__(self, world, speed=1):
Turtle.__init__(self, world, type='wanderer')
self.delay = 0
self.speed = speed
self.shape = 'Turtle'
# move to the starting position
self.pu()
self.rt(random.randint(0,360))
self.bk(150)
self.type = type
def wander(self):
# pick a direction randomly
def stalk(self):
# pick a direction facing another turtle
def step(self):
"""step is invoked by TurtleWorld on every Turtle, once
per time step."""
if self.type == 'wanderer':
self.wander()
elif elf.type == 'stalker':
self.stalk()
self.move()
def move(self):
"""move forward in proportion to self.speed"""
self.fd(self.speed)
def steer(self):
"""Coose a random direction for optimum dancing"""
self.rt(random.randint(-360,360))
def make_world():
# create TurtleWorld
world = TurtleWorld()
world.delay = .01
world.setup_run()
# create three dancers
Disco(world, 1, 'stalker')
Disco(world, 2)
Disco(world, 10)
return world
if __name__ == '__main__':
world = make_world()
world.mainloop() # calls Turtle.step() repeatedly