0

I am a newbie in VPython and I try to run very simple code from examples.

The following code works perfectly at glowscript.org :

Web VPython 3.2
coaster = curve(vector(-3,0,0),vector(-3,0,0))
theta = pi
d_theta = pi/100
while (theta <= 3*pi/2):
    theta += d_theta
    coaster.append(3*vector(cos(theta),sin(theta),0))

while (theta <= 2*pi):
    theta += d_theta
    coaster.append(5*vector(cos(theta),sin(theta),0)+vector(0,2,0))

cart = sphere(pos=coaster.point(0).pos+vector(0.1,0.1,0),color=color.red,radius=0.1,speed=0,mass=1)
g = 1

But when I tried to run it in JupyterLab with the following code :

canvas()

coaster = curve(vector(-3,0,0),vector(-3,0,0))
theta = pi
d_theta = pi/100
while (theta <= 3*pi/2):
    theta += d_theta
    coaster.append(3*vector(cos(theta),sin(theta),0))

while (theta <= 2*pi):
    theta += d_theta
    coaster.append(5*vector(cos(theta),sin(theta),0)+vector(0,2,0))

cart = sphere(pos=coaster.point(0).pos+vector(0.1,0.1,0),color=color.red,radius=0.1,speed=0,mass=1)
g = 1

The coaster curve is drawn. But, the sphere did not appear because I got the following error : AttributeError: 'dict' object has no attribute 'pos'. Indeed, coaster.point(0) is a simple dictionary :

{'pos': vector(-3, 0, 0),
 'color': vector(1, 1, 1),
 'radius': 0,
 'visible': True,
 'retain': -1}

And pos is a key, not a property of an object.

For info, the vpython version is 7.6.5.

So, I wonder if it is possible to use the same code in a JupyterLab cell and at at glowscript.org ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.