Accueil
Rechercher:
sur developpez.com sur les forums
Forums | Tutoriels | F.A.Q's | Participez | Hébergement | Contacts
Accueil Conception Java DotNET Visual Basic  C  C++ Delphi MS-Office SQL & SGBD Oracle  4D  Business Intelligence
Club Emploi Blogs   TV   Dév. Web PHP XML Python Autres 2D-3D-Jeux Sécurité Windows Linux PC Mac
FORUM PYTHON F.A.Q PYTHON TUTORIELS PYTHON SOURCES PYTHON OUTILS PYTHON LIVRES PYTHON
Description of Objects in VPython

Additional Attributes

The following attributes apply to all VPython objects:

visible If false (0), object is not displayed; e.g. ball.visible = 0
Use ball.visible = 1 to make the ball visible again.

frame Place this object into a specified frame, as in ball = sphere(frame = f1)

display When you start a VPython program, for convenience Visual creates a display window and names it scene. By default, objects you create go into that display window. You can choose to put an object in a different display like this:

        scene2 = display( title = "Act IV, Scene 2" )
        rod = cylinder( display = scene2 )
The function display.get_selected() returns a reference to the display in which objects are currently being created.

__class__ Name of the class of object. For example, ball.__class__ is sphere is true if ball is a sphere object. There are two underscores before and after the word class. In a list of visible objects provided by scene.objects, if obj is in this list you can determine the class of the object with obj.__class__.

__copy()__ Makes a copy of an object. There are two underscores before and after the copy(). Without any arguments, this results in creating a second object in the exact same position as the first, which is probably not what you want. The __copy__() function takes a list of keyword=value argument pairs which are applied to the new object before making it visible. For example, to clone an object from one display to another, you would execute: new_object = old_object.__copy__( display=new_display). Restriction: If the original object is within a frame, and the new object is on a different display, you must supply both a new display and a new frame for the new object (the new frame may be None). This is due to the restriction that an object may not be located within a frame that is in a separate display. The attribute __members__ used to give a list of all the object's attributes but is no longer available in VPython. Its main use was in copying objects.

Here is an example that uses the __copy()__ function. The following routine copies all of the Visual objects currently existing in one display into a previously defined second display:

def clone_universe( new_display, old_display):
        # Create a dictionary of frames in the old display
        # to the corresponding frames in the new display.
        frames = dict()
        # Initialize the lookup dictionary
        for obj in old_display.objects:
                if obj.__class__ == frame:
                        frames[obj] = obj.__copy__( frame=None, display=new_display)
        # For each old reference frame that was within another reference frame,
        # place the new reference frame within the appropriate frame in the new
        # display. Here old is an object and new is its frame in the new display.
        for old, new in frames.iteritems():
                if old.frame:
                        new.frame = frames[old.frame]
        # Copy over the universe.
        for obj in old_display.objects:
                if obj.__class__ == frame:
                        # Already taken care of above.
                        continue
                if obj.frame:
                        # Then initialize with the corresponding reference frame in the new
                        # display.
                        obj.__copy__( display=new_display, frame=frames[obj.frame])
                else:
                        # Don't need to care about the frame attribute, since it is None.
                        obj.__copy__( display=new_display)

See Controlling One or More Visual Display Windows for more information on creating and manipulating display objects.

 


Responsable bénévole de la rubrique Python : Guillaume Duriaud - Contacter par EMail :
Vos questions techniques : forum d'entraide Python - Publiez vos articles, tutoriels et cours
et rejoignez-nous dans l'équipe de rédaction du club d'entraide des développeurs francophones
Nous contacter - Copyright © 2000-2008 www.developpez.com - Legal informations.