mismatch between display and position value of objects

24 views
Skip to first unread message

Haim Edri

unread,
Jan 15, 2017, 5:24:15 AM1/15/17
to VPython-users
Hi

I wrote this small exercise for my students (to eventually create MD simulation).

I found it strange that the last ball at the last second does not align with the others, although it's position is seem to be correct (when printed it  looks right) 

I noticed that even if I try to update one of the ball's position outside the loops (at the end of the code) - the value changes but the animation don't.

whould love to get help..

The code: 

from visual import *
table = box(size=(11,11,0))

x=[]
i=-5
while i <= 5:
    ball = sphere(pos = (i,-5,0) ,radius = 0.4, color=color.red)
    x.append(ball)
    i=i+1

t=0
while t < 2:
   
    i=0
    while i<=10:
        rate(10)
        x[i].pos.y = x[i].pos.y+1.0
        print(i,x[i].pos.y)
        i = i + 1
     
    t=t+1

Steve Spicklemire

unread,
Jan 15, 2017, 5:29:32 AM1/15/17
to vpytho...@googlegroups.com, Steve Spicklemire
Hi Haim,

When I run your code, I see no terrible misalignment. Is it very subtle? What platform/version of VPython are you running?

thanks,
-steve


-- 
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Haim Edri

unread,
Jan 15, 2017, 6:04:04 AM1/15/17
to VPython-users
I use Idle, and when I run the code, I get:


but when I print  the position, the last ball has the same position as the rest of the balls (x[10].pos.y=-3)

Steve Spicklemire

unread,
Jan 15, 2017, 6:06:58 AM1/15/17
to vpytho...@googlegroups.com, Steve Spicklemire
Sounds like you need one more call to “rate(10)” although usually, after your program exits, VPython drops into an ‘exit’ routine that calls the rate() function repeatedly. It *sounds* like that’s not happening for you somehow. What version?

thanks,
-steve

> On Jan 15, 2017, at 6:04 AM, Haim Edri <edri....@gmail.com> wrote:
>
> I use Idle, and when I run the code, I get:
>
>
>

Haim Edri

unread,
Jan 15, 2017, 6:42:02 AM1/15/17
to VPython-users, stevespi...@gmail.com
I tried to add another rate(10) - it didn't help.
I also noticed that if i write another line after the loops end that update the position - the animation ignores it, although it is stored in the shapes attribute.

my python (and idle) version is 2.7.9 

any ideas?

Steve Spicklemire

unread,
Jan 15, 2017, 9:08:29 AM1/15/17
to Haim Edri, Steve Spicklemire, VPython-users
Hi Edri,

Can you send your new code with the added rate() call?

Also, what happens when you type:

>>> import visual
>>> visual.version
('6.11', 'release')
>>>

into the VIDLE shell?

thanks,
-steve

Bruce Sherwood

unread,
Jan 15, 2017, 9:12:36 AM1/15/17
to VPython-users, Haim Edri, Steve Spicklemire
The problem is that you are using IDLE. You need to use VIDLE, which is part of the Classic VPython installation.

Haim Edri

unread,
Jan 15, 2017, 4:49:03 PM1/15/17
to VPython-users, edri....@gmail.com, stevespi...@gmail.com
problem solved - it works just fine with VIDLE!!

Thanks!
Reply all
Reply to author
Forward
0 new messages