3d surface plot animation

"Poul Riis" <Poul.Riis-pIBpe43/vk1knbxzx/[email protected]>
Newsgroups gmane.comp.python.visualpython.user
Message-ID <[email protected]>
 

I have slightly modified the faces_heightfield example in order to add
another surface (see below).
That works fine but how can I get rid of the old surface (not just make it
invisible)?
My long-term-purpose is to make an animation (the zvalues depending on
time).


Poul Riis

## Demonstrates some techniques for working with "faces", and
## shows how to build a height field (a common feature request)
## with it.
## David Scherer July 2001
## Revised January 2010 by Bruce Sherwood to use faces.smooth() function
##   introduced with VPython 5.2
## Revised March 2010 by Bruce Sherwood to use faces.make_normals() and
## faces.make_twosided() functions introduced with VPython 5.3

from visual import *
from time import *

class Model:
    def __init__(self):
        self.frame = frame()
        self.model = faces(frame=self.frame, color=color.cyan)
        self.vertices = []

    def FacetedTriangle(self, v1, v2, v3, color=color.white):
        """Add a triangle to the model"""
        for v in (v1,v2,v3):
            self.vertices.append(v)

    def FacetedPolygon(self, *v):
        """Appends a planar polygon of any number of
vertices to the model"""
        for t in range(len(v)-2):
            self.FacetedTriangle( v[0], v[t+1], v[t+2] )

    def DrawNormals(self, scale):
        pos = self.model.pos
        normal = self.model.normal
        for i in range(len(pos)):
            arrow(pos=pos[i], axis=normal[i]*scale)

class Mesh (Model):
    def __init__(self, xvalues, yvalues, zvalues):
        Model.__init__(self)

        points = zeros( xvalues.shape + (3,), float )
        points[...,0] = xvalues
        points[...,1] = yvalues
        points[...,2] = zvalues

        for i in range(zvalues.shape[0]-1):
            for j in range(zvalues.shape[1]-1):
                self.FacetedPolygon( points[i,j], points[i,j+1],
                                     points[i+1,j+1], points[i+1,j] )
                
        self.model.pos = self.vertices
        self.model.make_normals()
        self.model.smooth()
        self.model.make_twosided()

## Graph a function of two variables (a height field)
x = arange(-1,1,2./20)
y = arange(-1,1,2./20)

z = zeros( (len(x),len(y)), float )
x,y = x[:,None]+z, y+z

Mesh( x, (sin(x*pi)+sin(y*pi))*0.2, y )
sleep(1)
Mesh( x, (sin(x*pi)+sin(2*y*pi))*0.2, y )

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct

_______________________________________________
Visualpython-users mailing list
Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/visualpython-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.