Take a look at this program, and run it:
http://www.glowscript.org/#/user/Bruce_Sherwood/folder/Examples/program/Bounce-VPython/edit
The program looks exactly like a VPython program and behaves the same. The goal is to be able to run the same (or very nearly the same) code either in the classic VPython environment, the IPython environment that John Coady has built (the ivisual module), or in the GlowScript environment.
You can help in this endeavor by writing test routines at
glowscript.org or by copying an existing VPython program to
glowscript.org and reporting problems you may see at this experimental stage. There are some caveats:
As you'll see in the program whose link is shown above, the developmental header line must be
GlowScript 1.2dev VPython
If you copy this code (minus the header line) to a classic VPython file, with the header "from visual import *", the program will run with no changes.
At the moment, the GlowScript assumption is that your program is designed for "from visual import *", which is implicit. It is intended also to support other flavors ("from visual import box, cylinder", "import visual", "from vis import box, cylinder", and "import vis"). Standard in GlowScript (due to the nature of the underlying JavaScript) is that 1/2 is 0.5, not 0.
The curve object is that of GlowScript/RapydScript, which is somewhat different from the classic VPython curve. See the GlowScript Help for how to deal with curve.
make_trail has not been implemented.
I intend to provide a conversion program to deal with the following differences:
In creating an object such as a box, it is obligatory to specify pos, axis, size, color, and up as vectors, which can be written either as "vector" or as "vec". It is intended to update classic VPython to accept "vec", but you can achieve this effect in classic VPython by starting a program with the statement "vec = vector".
If you say b = box() and want to change its x position you must refer to b.pos.x, not b.x.
Change "scene.mouse.getclick()" to "scene.waitfor('click')", which works in either environment.
"scene.title(...)" must be changed to "scene.title.text(....)" or "scene.title.html(...)".
Some things are likely to require manual intervention for a while, including curve, materials (GlowScript textures), and testing two vectors for equality. In classic VPython you can say "if A == B:", where A and B are vectors, but in GlowScript you must say "if A.equals(B)", and VPython should be changed to accept this form. There is pick but no 3D pickpos functionality in GlowScript. GlowScript still doesn't handle keyboard events, except to type into a text area. Graphing compatibility has not really been addressed yet, but both environments ought to accept either g.plot(x,y) as in current GlowScript or g.plot(pos=(x,y)) as in current classic VPython.
The key point of this new GlowScript option is that although the basic GlowScript syntax is very similar to that of classic VPython, the details of the semantics are rather different. In particular, in classic VPython changing axis affects the length attribute of the size, and changing the length attributed affects the magnitude of the axis. The new GlowScript/VPython option mimics the behavior/semantics of classic VPython, in recognition that a large amount of VPython code exists that is worth porting to the browser. For GlowScript users who want to write in a Python-like language but prefer the original GlowScript semantics, they can choose RapydScript.
This development has been made possible by the Python-to-JavaScript compiler, RapydScript, and by the help of the RapydScript community in the persons of Alexander Tsepkov, Charles Law, and Salvatore di Dio.