|
149 | 149 | from vypthon import box, color # or (box, color)</p>
|
150 | 150 | <div> </div>
|
151 | 151 | <p class="Normal"><span class="style1">For those who have used Classic VPython</span></p>
|
152 |
| -<p class="Normal">A few Classic VPython objects are not currently available in GlowScript: convex, faces, and frame. The GlowScript objects <a href="../GlowScriptDocs/vector.html" target="_blank">vertex</a>, <a href="../GlowScriptDocs/triangle.html" target="_blank">triangle</a>, and <a href="../GlowScriptDocs/triangle.html" target="_blank">quad</a> represent a more powerful alternative to faces. Many applications of frame can be handled with the GlowScript <a href="../GlowScriptDocs/compound.html" target="_blank">compound</a> object. The extrusion object and the paths and shapes libraries currently have many fewer features than the Classic version.</p> |
| 152 | +<p class="Normal">A few Classic VPython objects are not currently available in GlowScript: convex, faces, and frame. The GlowScript objects <a href="../GlowScriptDocs/vector.html" target="_blank">vertex</a>, <a href="../GlowScriptDocs/triangle.html" target="_blank">triangle</a>, and <a href="../GlowScriptDocs/triangle.html" target="_blank">quad</a> represent a more powerful alternative to faces. Many applications of frame can be handled with the GlowScript <a href="../GlowScriptDocs/compound.html" target="_blank">compound</a> object. </p> |
153 | 153 | <p class="Normal">One way to deal with differences is to check the elements of the "version" variable that is available in both Classic VPython and the GlowScript version and do different things in the different environments:</p>
|
154 | 154 | <p class="program">Classic VPython: version is ['X.Y', 'release']<br />
|
155 |
| - GlowScript VPython: version is ['X.Y', 'glowscript'] </p> |
| 155 | + GlowScript VPython: version is ['X.Y', 'glowscript']<br /> |
| 156 | + Jupyter VPython: version is ['X.Y.Z', 'jupyter']<br /> |
| 157 | + and in Jupyter VPython, the version of the GlowScript<br /> |
| 158 | + graphics library is given by<br /> |
| 159 | + GSversion is ['X.Y', 'glowscript']</p> |
156 | 160 | <p class="Normal">The <a href="../GlowScriptDocs/curve.html">curve</a> and <a href="points.html">points</a> objects are somewhat different in the GlowScript environment, but with a little care it is possible to use these objects in such a way that they will also work in Classic VPython. Note that in GlowScript the list of points in a curve object is not a numpy array, so that a loop is required to change all of the points.</p>
|
157 | 161 | <p class="Normal">To handle <a href="mouse.html"><strong>mouse events</strong></a> one cannot use scene.getevent() but must use scene.bind(), which is available both in Classic VPython 6 and in GlowScript. Also available are scene.pause() and scene.waitfor('click') and related options.</p>
|
158 | 162 | <p class="Normal">It is not possible to import arbitrary Python modules such as numpy, and any VPython program that uses numpy will have to be modifed. However, loops are fast in the JavaScript language to which GlowScript programs compile, so if you are using numpy solely for the speed of array manipulation, you may be able to replace a numpy calculation easily and efficiently with a loop.</p>
|
|
163 | 167 | <div>
|
164 | 168 | <p class="Normal">GlowScript treats 3/2 as 1.5 as in Python 3.x, not 1 as in the Python 2.x language, and the print statement must take the Python 3.x form of print('hello') rather than the Python 2.x form of print 'hello'.</p>
|
165 | 169 | </div>
|
166 |
| -<p class="Normal">Many programs written in Classic <a href="http://vpython.org" target="_blank"><strong>VPython 6</strong></a> will run in GlowScript without change after being run through a <a href="../GlowScriptDocs/VPtoGS.py" target="_blank"><strong>conversion program</strong></a> written in Python. This program converts<strong> (x,y,z) => vector(x,y,z)</strong> and <strong>obj.x => obj.pos.x</strong>. These changes are necessary because GlowScript does not recognize <strong>(x,y,z)</strong> as a vector nor <strong>obj.x</strong> as a shorthand for <strong>obj.pos.x</strong>. The program also converts <strong>display => canvas</strong> and <strong>gdisplay => graph</strong>.</p><
5D09
/div> |
| 170 | +<p class="Normal">Many programs written in Classic <a href="http://vpython.org" target="_blank"><strong>VPython 6</strong></a> will run in GlowScript or Jupyter without change after being run through a <a href="../GlowScriptDocs/VPtoGS.py" target="_blank"><strong>conversion program</strong></a> written in Python. This program converts<strong> (x,y,z) => vector(x,y,z)</strong> and <strong>obj.x => obj.pos.x</strong>. These changes are necessary because GlowScript does not recognize <strong>(x,y,z)</strong> as a vector nor <strong>obj.x</strong> as a shorthand for <strong>obj.pos.x</strong>. The program also converts <strong>display => canvas</strong> and <strong>gdisplay => graph</strong>.</p> |
167 | 171 | <p class="Normal"> In the GlowScript environment pos, size, axis, color, and up are all vectors, and they are somewhat special vectors that track changes in order to trigger correct rendering of the 3D scene when one of these object attributes changes. One result of this architecture is that <br />
|
168 | 172 | <br />
|
169 | 173 | <strong> ball.pos += vector(1,2,3)</strong><br />
|
|
0 commit comments