vpython / vpython-jupyter

3D visualization made easy
MIT License
138 stars 65 forks source link

vpython: scene.camera.follow(function) does NOT work #199

Closed horstjens closed 2 years ago

horstjens commented 2 years ago

using latest vpython version from github, scene.follow(None) does work now, but letting the camera follow a function as described in the documentation https://www.glowscript.org/docs/VPythonDocs/canvas.html does NOT work. (I guess it also did not worked before the patch).

(tested on Ubuntu Linux 21.10, python 3.9.7, latest vpython version from github (patch #198 )

The problem can be reproduced using idle:

import vpython as vp b = vp.box() vp.scene.camera.follow(b) vp.scene.camera.follow(None) # works ! def f(): ... return 2*b.pos ... vp.scene.camera.follow(f) # does NOT work Traceback (most recent call last): File "", line 1, in File "/home/horst/code/vpython/github version/vpython-jupyter-master/vpython/vpython.py", line 2940, in follow self.addmethod('follow', obj.idx) AttributeError: 'function' object has no attribute 'idx

BruceSherwood commented 2 years ago

Yes, the documentation should say that this is not (yet) supported with installed Python.

BruceSherwood commented 2 years ago

To enable following based on a function, replace site-packages/vpython/vpython.py with https://github.com/vpython/vpython-jupyter/blob/master/vpython/vpython.py This will be included in future releases of the vpython module.