From: Bruce S. <Bru...@nc...> - 2013-01-13 18:26:11
|
Here's an improved version of the differences between VPython 5 and 6; Changes from VPython 5 VPython 6 will run almost all old VPython programs correctly without change The following details about changes may be important in a few unusual cases. An animation loop must contain a rate or sleep statement, which limits the number of loop iterations per second as before but also when appropriate (about 30 times per second) updates the 3D scene and handles mouse and keyboard events. Without a rate or sleep statement, the scene will not be updated until and unless the loop is completed. Most animation loops already contain a rate statement anyway, to make the animation not run too fast. You should use the new function sleep rather than time.sleep. The new function periodically renders the scene and processes mouse events, making it possible to continue using zoom and rotate, whereas time.sleep does not do this. Programs that use time.sleep will work, but you won't be able to zoom or rotate during the sleep period. You must import visual or vis before importing graph or controls or filedialog, which most users have always done anyway. *Your own program is imported by VPython:* For technical reasons, it is necessary for VPython 6 to do something rather unusual. When you import visual (or vis), your own program is in turn imported by the visual module. For this reason, you should import visual near the start of your program, because any executable statements preceding the import will be executed twice. The import of visual is also re-executed, but this is harmless because in Python a repeated import doesn't repeat the calculations in the imported module. *Importing your own modules:* If you create your own module (lib.py, say) that imports visual, and you import lib from a program named demo.py, you need to import visual in demo.py before importing lib, so that demo is the base program (when lib imports visual, that will be the second import of visual and will not lead to lib being imported by visual). Note that the standard trick of testing a module on the basis of __name__=='__main__' won't work, because the program will be imported by visual. To test a module, import it from a test program rather than trying to use __name__=='__main__' within the module. |