VPython not rendering position changes

27 views
Skip to first unread message

Sam McCormack

unread,
Dec 21, 2016, 5:14:12 PM12/21/16
to VPython-users
I am writing a VPython simulation of multiple bouncing balls. I have used a class and a list to shorten the code and easily allow for a different number of balls. However, although the code knows that the positions and momenta of the balls are changing rapidly, the display window does not render any changes. I have tested using VIDLE and Glowscript, and they both have the same issue. I used a print function to verify that the positions and momenta are changing as they should.
So, what am I doing wrong? Any help would be greatly appreciated :)

The code can be found here:

Steve Spicklemire

unread,
Dec 21, 2016, 5:21:29 PM12/21/16
to vpytho...@googlegroups.com, Steve Spicklemire
Hi Sam,

You can’t set ‘self’ in the __init__ method of your class.

Try this:

class Ball:
def __init__(self, pos, radius):
self.pos = pos
self.radius = radius
self.s = sphere(pos = self.pos, radius = self.radius, color = color.red)

then in your update loop:

ball.s.pos = ball.s.pos + ball.v * dt

-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.

Sam McCormack

unread,
Dec 21, 2016, 5:29:33 PM12/21/16
to VPython-users, stevespi...@gmail.com
Thanks for your reply! That works a treat, thanks for saving me a load more time trying to figure out what was wrong with it :)
Reply all
Reply to author
Forward
0 new messages