forked from myrlund/salabim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo animate 2.py
53 lines (37 loc) · 1.24 KB
/
Demo animate 2.py
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
# Demo animate 2.py
import salabim as sim
class AnimateWaitSquare(sim.Animate):
def __init__(self, i):
self.i = i
sim.Animate.__init__(self,
rectangle0=(-10, -10, 10, 10), x0=300 - 30 * i, y0=100, fillcolor0='red', linewidth0=0)
def visible(self, t):
return q[self.i] is not None
class AnimateWaitText(sim.Animate):
def __init__(self, i):
self.i = i
sim.Animate.__init__(self, text='', x0=300 - 30 * i, y0=100, textcolor0='white')
def text(self, t):
component_i = q[self.i]
if component_i is None:
return ''
else:
return component_i.name()
def do_animation():
env.animation_parameters()
for i in range(10):
AnimateWaitSquare(i)
AnimateWaitText(i)
show_length = sim.Animate(text='', x0=330, y0=100, textcolor0='black', anchor='w')
show_length.text = lambda t: 'Length= ' + str(len(q))
class Person(sim.Component):
def process(self):
self.enter(q)
yield self.hold(15)
self.leave(q)
env = sim.Environment(trace=True)
q = sim.Queue('q')
for i in range(15):
Person(name='{:02d}'.format(i), at=i)
do_animation()
env.run()