Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Controlling Speed of a Moving Canvas

Hi all,

I have a script that practically create a circle and move it in a certain angle.

import numpy

my_canvas   = canvas()
BigR            = 150
SmallR          = BigR*5/6
xTiny0      = 0.01
yTiny0      = SmallR+((BigR-SmallR)/2)
RTiny       = (BigR-SmallR)/1.5
RES         = 200 # step resolution
TIME        =1# seconds
R           = yTiny0 # Circle radius

def move_by_angle(origin, angle, r):

    alpha = numpy.arctan(origin[1] / origin[0])
    angle_step = angle/RES

    path = []
    for point in range(0, RES):
        beta = alpha + point*angle_step
        path.append ([r*numpy.sin(beta), r*numpy.cos(beta)])
    return path

start = [yTiny0,xTiny0] * R
angle = numpy.pi*-0.5
path = move_by_angle(start, angle, R)

for step in range(0, RES):
    xTiny0, yTiny0 = path[step][0], path[step][1]
    TinyCircle =, yTiny0, RTiny, fill=True, color= '#404040')

Though it works, my limited experience with programming is facing me with a problem. My problem is that the moving circle has sort of "innate speed"; it seems like the last "for" loop enforce the circle a speed that i'm not sure how to control. My goal is to determine or measure the speed and to change it according to a certain radius or angle.

Can anyone help me with that?



  • Hi,

    If you use the psycho or xpyriment backend, the display presentation will be locked to the refresh rate. That is, if your refresh rate is 60Hz, then will be executed 60 times per second. (Or less if you're doing very time-consuming things in between, but I doubt that's a problem here. But never more!)

    So the steps would be to:

    1. Determine the refresh rate of the monitor
    2. Check the timestamps returned by to verify that it's indeed tracking the refresh rate
    3. From there, determine the correct RES.

    By the way, your trigonometry seems correct, but not particularly elegant. Here you can see a more Pythonic approach:


  • Thank you so much!!!

Sign In or Register to comment.