I would need the dsi/centres.npy to test your example.
If that can help, here is the boids example with a background image.
Nicolas
-----
import numpy as np
import OpenGL.GL as gl
from scipy.spatial import cKDTree
from glumpy import figure, Trackball, image
if __name__ == '__main__':
fig = figure(size=(800,800))
frame = fig.add_frame()
trackball = Trackball(65, 135, 1., 2.0)
Z = np.random.random((32,32)).astype(np.float32)
image = image.Image(Z)
@frame.event
def on_mouse_drag(x, y, dx, dy, button):
trackball.drag_to(x,y,dx,dy)
fig.redraw()
@fig.event
def on_draw():
fig.clear(0.95,0.95,0.95,1)
frame.lock()
frame.draw()
trackball.push()
gl.glEnable(gl.GL_BLEND)
gl.glEnable(gl.GL_POINT_SMOOTH)
for i,P in enumerate([boids['position'],
boids['position_1'],
boids['position_2']]):
gl.glColor(0+i*.25,0+i*.25,0+i*.25,0.5)
gl.glPointSize(6.0-i)
gl.glBegin(gl.GL_POINTS)
for j in range(len(boids)):
gl.glVertex( P[j,0], P[j,1], P[j,2] )
gl.glEnd()
trackball.pop()
image.draw( x=0, y=0, z=0, width=frame.width, height=frame.height )
frame.unlock()
@frame.timer(60.0)
def timer(dt):
global t
t += 0.5*dt
target[...] = np.array([np.sin(t),np.sin(2*t),np.cos(3*t)])*.1
t += 0.5*dt
predator[...] = np.array([np.sin(t),np.sin(2*t),np.cos(3*t)])*.2
boids['position_2'] = boids['position_1']
boids['position_1'] = boids['position']
n = len(boids)
P = boids['position']
V = boids['velocity']
# Cohesion: steer to move toward the average position of local flockmates
C = -(P - P.sum(axis=0)/n)
# Alignment: steer towards the average heading of local flockmates
A = -(V - V.sum(axis=0)/n)
# Repulsion: steer to avoid crowding local flockmates
D,I = cKDTree(P).query(P,5)
M = np.repeat(D < 0.05, 3, axis=1).reshape(n,5,3)
Z = np.repeat(P,5,axis=0).reshape(n,5,3)
R = -((P[I]-Z)*M).sum(axis=1)
# Target : Follow target
T = target - P
# Predator : Move away from predator
dP = P - predator
D = np.maximum(0, 0.1 - np.sqrt(dP[:,0]**2 +dP[:,1]**2+dP[:,2]**2) )
D = np.repeat(D,3,axis=0).reshape(n,3)
dP *= D
boids['velocity'] += 0.0005*C + 0.01*A + 0.01*R + 0.0005*T + 0.0025*dP
boids['position'] += boids['velocity']
fig.redraw()
t = 0
n = 1000
boids = np.zeros(n, [ ('position', 'f4', 3),
('position_1', 'f4', 3),
('position_2', 'f4', 3),
('velocity', 'f4', 3)] )
boids['position'] = np.random.uniform(-0.25, +0.25, (n,3))
boids['velocity'] = np.random.uniform(-0.00, +0.00, (n,3))
target = np.zeros(3)
predator = np.zeros(3)
fig.show()