Weird "rate" behaviour

78 views
Skip to first unread message

Mathijs Saey

unread,
Oct 28, 2015, 4:37:20 PM10/28/15
to VPython-users
Hello,

I am working on a small project in VPython and I ran into some strange behaviour.
Consider the following piece of code which simply moves a sphere to random spots in a window.

from visual import *
import random

random
.seed()

canvas
= display(autocenter = False, autoscale = False, userzoom = 0)
canvas
.width = 800
canvas
.height = 600
canvas
.range = (800, 1, 1)
canvas
.center = (0, 550)
canvas
.select()

test
= sphere(radius = 20, pos = (100,100))

while True:
  rate
(60)
  x
= random.randint(0, 800 - 1)
  y
= random.randint(0, 600 - 1)
  test
.pos = vector(x,y)

For some odd reason, the canvas is only updated at the appropriate speed when some form of interaction is going on (i.e. when I move the mouse or when I press a key).
When this is not the case, the animation updates far slower than it should.

Is this just me misunderstanding the behavior of rate? Or did I run into a VPython bug here?

I'm running VPython 6.11 on python 2.7.10 on OSX 10.11

Steve Spicklemire

unread,
Oct 28, 2015, 5:28:46 PM10/28/15
to vpytho...@googlegroups.com
Can you describe how you installed VPython?

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.

Bruce Sherwood

unread,
Oct 28, 2015, 6:02:22 PM10/28/15
to vpytho...@googlegroups.com
Your programs works for me on Mac and Windows, which suggests something went wrong in the installation process. As Steve suggested, it would be useful to know the details of how you installed VPython.

Minor comments:

The statement "canvas.select()" is superfluous, as the most recently created display is the one the sphere will go into.

I think you probably meant "canvas.center = (canvas.width/2, canvas.height/2)" to use the full display. Similarly, "canvas.range = 400" will make the positions populate the full display; 400 is the maximum distance from the center to the edge.

Mathijs Saey

unread,
Oct 28, 2015, 6:28:43 PM10/28/15
to VPython-users
I used homebrew to install VPython, so the problem could be on their end.
In case it's important, here is the formula I used for the installation: https://github.com/Homebrew/homebrew-python/blob/master/vpython.rb


I think you probably meant "canvas.center = (canvas.width/2, canvas.height/2)" to use the full display. Similarly, "canvas.range = 400" will make the positions populate the full display; 400 is the maximum distance from the center to the edge.

You're right, I copy pasted some older code for my example, which is probably how that managed to sneak in there.
I didn't know about the maximum distance, thanks!

Steve Spicklemire

unread,
Oct 28, 2015, 6:49:05 PM10/28/15
to vpytho...@googlegroups.com
OK, my guess is you have installed two recent version of WXwindows. 

Can you try:

brew list wxmac 



thanks,
-steve

Steve Spicklemire

unread,
Oct 28, 2015, 6:50:37 PM10/28/15
to vpytho...@googlegroups.com
Ack!

"too" recent I mean. Auto spell/correct doesn't always get it right.

thanks,
-steve

Steve Spicklemire

unread,
Oct 28, 2015, 6:55:46 PM10/28/15
to vpytho...@googlegroups.com
Ack!

"too" recent I mean. Auto spell/correct doesn't always get it right.

thanks,
-steve

On Oct 28, 2015, at 6:49 PM, Steve Spicklemire <stevespi...@gmail.com> wrote:

Mathijs Saey

unread,
Oct 28, 2015, 6:58:30 PM10/28/15
to VPython-users
I seem to have version 3.0.2:

$ brew list wxmac
/usr/local/Cellar/wxmac/3.0.2/bin/wx-config
/usr/local/Cellar/wxmac/3.0.2/bin/wxrc
/usr/local/Cellar/wxmac/3.0.2/bin/wxrc-3.0
/usr/local/Cellar/wxmac/3.0.2/include/wx-3.0/ (730 files)
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_baseu-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_baseu_net-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_baseu_xml-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_adv-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_aui-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_core-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_gl-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_html-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_media-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_propgrid-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_qa-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_ribbon-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_richtext-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_stc-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_webview-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/libwx_osx_cocoau_xrc-3.0.0.2.0.dylib
/usr/local/Cellar/wxmac/3.0.2/lib/wx/ (2 files)
/usr/local/Cellar/wxmac/3.0.2/lib/ (32 other files)
/usr/local/Cellar/wxmac/3.0.2/share/aclocal/wxwin.m4
/usr/local/Cellar/wxmac/3.0.2/share/bakefile/ (5 files)
/usr/local/Cellar/wxmac/3.0.2/share/locale/ (22 files)

Steve Spicklemire

unread,
Oct 28, 2015, 7:02:27 PM10/28/15
to vpytho...@googlegroups.com, Steve Spicklemire
I would suggest you revert to version 3.0.0 and try again. Something broke after 3.0.0 on OSX and wx no longer wants to process our manual event loop (implemented in the rate() command) correctly.

There’s some info about installing specific versions of home-brew “formulae” here:

<http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula>

I’m not really a brew expert (brewmaster?) but I might be able to help if you run into trouble.

-steve

Mathijs Saey

unread,
Oct 28, 2015, 8:46:35 PM10/28/15
to VPython-users, stevespi...@gmail.com
Installing 3.0.0 through homebrew did not seem to work, so I decided to just install Python 2.7 and Vpython through their "standard" installers for now. This messes with my homebrew set up, but it doesn't break anything, so I'll stick to this for the time being.
Thanks for all the help, I would have probably never figured out that my wxwidgets version would be the root of the issue!

Steve Spicklemire

unread,
Oct 28, 2015, 9:05:55 PM10/28/15
to Mathijs Saey, Steve Spicklemire, VPython-users
Hi Mathijs,

Hmm.. what does brew info wxmac say? Note the ‘*’ that indicates I’m currently running 3.0.0 not the 3.0.2 version.

You can also use python to check the version:

aluminum:~ steve$ python -c 'import wx; print wx.version()'
3.0.0.0 osx-cocoa (classic)

-steve

aluminum:~ steve$ brew info wxmac
wxmac: stable 3.0.2 (bottled)
wxWidgets, a cross-platform C++ GUI toolkit (for OS X)
https://www.wxwidgets.org
/usr/local/Cellar/wxmac/3.0.0.0 (2431 files, 110M) *
Built from source
/usr/local/Cellar/wxmac/3.0.2 (778 files, 41M)
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/wxmac.rb
==> Dependencies
Required: jpeg ✔, libpng ✘, libtiff ✘
==> Options
--with-static
build static libraries
--with-stl
use standard C++ classes for everything

Mathijs Saey

unread,
Oct 29, 2015, 6:47:20 AM10/29/15
to VPython-users, mathi...@gmail.com, stevespi...@gmail.com
Hello,

mathsaey@Anduin:~$ brew info wxmac
wxmac
: stable 3.0.2 (bottled)

wxWidgets
, a cross-platform C++ GUI toolkit (for OS X)
https
://www.wxwidgets.org
/usr/local/Cellar/wxmac/3.0.2 (777 files, 41M) *

 
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/wxmac.rb
==> Dependencies
Required: jpeg ✔, libpng ✔, libtiff
==> Options
--with-static
    build
static libraries
--with-stl
   
use standard C++ classes for everything

The python version returns 3.0.0 for now, since I've installed it through the pkg:

 mathsaey@Anduin:~$ python -c 'import wx; print wx.version()'
3.0.0.0 osx-cocoa (classic)

As far as I know, no older versions of wxwidgets are available on tap, I tried reverting the formula to an older version, but building failed when I tried that.
Reply all
Reply to author
Forward
0 new messages