-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimulator.py
56 lines (43 loc) · 1.12 KB
/
simulator.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
54
import matplotlib
matplotlib.use('TkAgg')
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize, LinearSegmentedColormap
from scipy.sparse import spdiags,linalg,eye
from time import sleep
cmap = LinearSegmentedColormap('divergent', {
'red': [(0., 0., 0.),
(0.5, 1., 1.),
(1., 1., 1.)],
'green': [(0., 0., 0.),
(0.5, 1., 1.),
(1., 0., 0.)],
'blue': [(0., 1., 1.),
(0.5, 1., 1.),
(1., 0., 0.)],
})
norm = Normalize(vmin=0., vmax=1., clip=True)
import sys
model = __import__(sys.argv[1])
#import example as model
space = model.Space()
space.init()
x = np.linspace(space.size_x[0], space.size_x[1], space._mx)
y = np.linspace(space.size_y[0], space.size_y[1], space._my)
plt.ion()
while True :
space.integrate(dt=space.resolution/2)
if True :
plt.clf()
# chemical field
U=space.fields[0].reshape((space._my,space._mx))
plt.pcolormesh(x,y,U, norm=norm, cmap=cmap)
plt.colorbar
plt.axis('image')
plt.title(str(space.t))
# agents
i = [a.pos[0] for a in space.agents]
j = [a.pos[1] for a in space.agents]
plt.scatter(i,j)
plt.draw()
plt.ioff()