How to animate outline and axes objects in mayavi

91 views Asked by At

I have a surface that is changing shape and size in time. I want to draw an outline around it with an axes that moves with it. I can remove and replace the outline and axes with each update but that's not very satisfying. Is there any way to update the existing axes and outline objects to detect changes to the underlying surface?

from mayavi import mlab

phi, theta = np.mgrid[0:2 * np.pi:12j, 0:np.pi:12j]

def make_sphere(r):
    x = r * np.cos(phi) * np.sin(theta)
    y = r * np.sin(phi) * np.sin(theta)
    z = r * np.cos(theta)
    return x, y, z


x,y,z = make_sphere(1)
mesh = mlab.mesh(x, y, z)
outline = mlab.outline(mesh)
axes = mlab.axes(color=(0, 0, 0))


def update(t):
    x,y,z = make_sphere(np.abs(np.random.randn(1)))
    mesh.mlab_source.reset(x=x, y=y, z=z)

@mlab.animate(delay=100)
def animate():
    for t in range(1, 1000):
        update(t)
        yield

animate()
mlab.show()

too small too big

0

There are 0 answers