3d surface plot animation

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

[email protected] writes:
>To hide a Visual object just make it invisible: ball.visible = False.
>This does not delete the object from computer memory, and you can make
>it visible again later.
>
>If however you later re-use the name ball, for example by creating a
>new object and naming it ball, Python will be free to release the
>memory used by the object formerly named ball (assuming no other names
>currently refer to that object). If the object is visible when you
>re-use the name ball, the original object will not be deleted from
>computer memory, and it will remain visible in the window.
>
>After you make an object named ball invisible, you can delete it
>immediately with del ball.

Oh, yes, that's from the manual. Nevertheless, I cannot make it work (see
below).

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

surface=Mesh( x, (sin(x*pi)+sin(y*pi))*0.2, y )
sleep(1)
surface.visible=False
del surface
surface=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.